开发者

Android ImageView and Bitmap on canvas don't have the same size

开发者 https://www.devze.com 2023-03-17 02:42 出处:网络
I have a Bitmap image in my ressources. When i draw it using an ImageView, it doesn\'t have the same size as when I draw it on the canvas using Drawbitmap.

I have a Bitmap image in my ressources.

When i draw it using an ImageView, it doesn't have the same size as when I draw it on the canvas using Drawbitmap. No matter what density I use to my bitmap ( 160, 240 ), the bitmap is always zoomed. How to draw the bitmap so it has the same size as when I use an image开发者_JAVA百科view ?


The trick is to create a scaled bitmap and then draw.

my_bitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.my_bitmap);
my_bitmap = Bitmap.createScaledBitmap(my_bitmap, screenWidth, screenHeight, true);
0

精彩评论

暂无评论...
验证码 换一张
取 消