【问题标题】:Fast load image from sdcard从 sdcard 快速加载图像
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多