开发者

how to reduce large image size to thumbnail size in android

开发者 https://www.devze.com 2023-03-11 04:31 出处:网络
in my app, i have large images, i display it in an image view by hard code the size as 60 X 60 dp. how to reduce the image size as image thumb nail size in android. is there programmatic way. because

in my app, i have large images, i display it in an image view by hard code the size as 60 X 60 dp. how to reduce the image size as image thumb nail size in android. is there programmatic way. because suppose i run my app in various resolution size design layout may get differ. my need is if i run my app in any resolution device image size should not get differ. how to do that in android. please help me.

i hard code image by the following code.

  <Im开发者_如何学JAVAageView android:id="@+id/img" android:layout_width="60dp"
     android:layout_height="60dp"
    android:layout_centerVertical="true" />


Most simple way is

int h = 48; // height in pixels
int w = 48; // width in pixels    
Bitmap scaled = Bitmap.createScaledBitmap(largeBitmap, h, w, true);

and detailed This is called the image scaling

This will help you http://zerocredibility.wordpress.com/2011/01/27/android-bitmap-scaling/


Add the following elements in your xml file:

android:scaleType="fitXY"
android:layout_width="48dip" 
android:layout_height="48dip"
0

精彩评论

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

关注公众号