So i have custom View, where i draw on canvas. I would like to add icon or some image on canvas. I tried with
canvas.setBackgroundResource(R.drawable.image_name)
The probleme here is that my icon is resized to fit the screen and i have no control to resize or scale image.
Maybe i can get height and width of canvas, and then create Drawable/bitmap with unscaled icon and fill the background with some color? Can anyone point me in the right direction?
Drawable icon = getResources().getDrawable(R.drawable.image_name);
icon.setBounds(left, top, right, bottom);
icon.draw(canvas);
You can use icon.getIntrinsicHeight()
and icon.getIntrinsicWidth()
to get the preferred size of the icon.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With