Java (Android) Paste Icon to Canvas
So, I have a custom view where I draw on a canvas. I would like to add an icon or image to the canvas. I tried with
canvas.setBackgroundResource(R.drawable.image_name)
The problem here is that my icon has been resized to fit the screen and I have no control to resize or scale the image.
Maybe I can get the height and width of the canvas and then create a Drawable / bitmap with an unscaled icon and fill the background with some color? Can anyone point me in the right direction?
+3
Phil Boris
source
to share
1 answer
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 your preferred icon size.
+6
pdegand59
source
to share