如何在android中将大图像尺寸缩小为缩略图尺寸 [英] how to reduce large image size to thumbnail size in android

查看:34
本文介绍了如何在android中将大图像尺寸缩小为缩略图尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我有大图像,我通过硬编码将其显示在图像视图中,大小为 60 X 60 dp.如何在android中将图像大小减小为图像缩略图大小.有没有程序化的方式.因为假设我以各种分辨率大小的设计布局运行我的应用程序可能会有所不同.我的需要是,如果我以任何分辨率运行我的应用程序,设备图像大小不应有所不同.如何在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. 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.

  <ImageView android:id="@+id/img" android:layout_width="60dp"
     android:layout_height="60dp"
    android:layout_centerVertical="true" />

推荐答案

最简单的方法是

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

和详细这称为图像缩放

这将帮助您http://zerocredibility.wordpress.com/2011/01/27/android-bitmap-scaling/

这篇关于如何在android中将大图像尺寸缩小为缩略图尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆