I know that to draw bitmap in canvas we need to call canvas.drawBitmap(filterBitmap, 0f, 0f, paint) for full screen image. But I couldn't understand why my code didn't work and my ImageView is empty.
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val bitmap = BitmapFactory.decodeResource(resources, R.drawable.grass)
val filterBitmap = Bitmap.createBitmap(bitmap.width, bitmap.height, bitmap.config)
val paint = Paint().apply {
color = Color.RED
style = Paint.Style.FILL
}
val canvas = Canvas(filterBitmap)
canvas.drawBitmap(filterBitmap, 0f, 0f, paint)
filter_image.setImageBitmap(filterBitmap)
}
Drawable resource has width and height.