从SD卡快速加载图像

时间:2014-01-25 07:10:13

标签: android image performance

我希望从sdcard加载图像到listview,但我不需要大尺寸的图像。尺寸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;}

1 个答案:

答案 0 :(得分:0)

检查android queryimage loading using android query

它非常快,试试吧。

File file = new File(path);        

//load image from file, down sample to target width of 300 pixels  
aq.id(R.id.avatar).image(file, 300);

您也可以使用Android-Universal-Image-Loader

String imageUri = "file:///mnt/sdcard/image.png"; // from SD card

// Load image, decode it to Bitmap and display Bitmap in ImageView (or any other view 
//  which implements ImageAware interface)

imageLoader.displayImage(imageUri, imageView);