2014-01-25 124 views
0

我想从sdcard加载图像到列表视图,但我不需要图像的大尺寸。大小60dip * 60dip是足够的。我在线程中使用下面的代码,但是这很慢。我需要快速加载图像。从SD卡快速加载图像

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;} 

回答

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);