简体   繁体   English

如何在 android 中将大图像尺寸缩小为缩略图尺寸

[英]how to reduce large image size to thumbnail size in android

in my app, i have large images, i display it in an image view by hard code the size as 60 X 60 dp.在我的应用程序中,我有大图像,我通过硬编码将其显示在图像视图中,大小为 60 X 60 dp。 how to reduce the image size as image thumb nail size in android.如何在 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.如何在 android 中做到这一点。 please help me.请帮我。

i hard code image by the following code.我通过以下代码对图像进行硬编码。

  <ImageView 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/这将对您有所帮助http://zerocredibility.wordpress.com/2011/01/27/android-bitmap-scaling/

Add the following elements in your xml file then you get your answer.在您的 xml 文件中添加以下元素,然后您就会得到答案。

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

I hope this is helpful to you.我希望这对你有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM