【发布时间】:2014-01-25 07:10:12
【问题描述】:
我希望将图像从 sdcard 加载到列表视图,但我不需要大尺寸的图像。尺寸 60dip * 60dip 就足够了。我在线程中使用下面的代码,但这很慢。我需要快速加载图像。
public Bitmap loadImage(String imagePath){
//load bitmap in real size
Bitmap bmp = BitmapFactory.decodeFile(imagePath);
int width = bmp.getWidth();
int height = bmp.getHeight();
//determine size and scale
float newWidth = convertDipToPixel(60, getApplicationContext());//60 dip
float scale = ((float) newWidth) / width;
// createa matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scale, scale);
Bitmap resizedBitmap = Bitmap.createBitmap(bmp, 0, 0, width, height, matrix, true);
return resizedBitmap;}
【问题讨论】:
标签: android image performance