how to compress image for imageview in android

前端 未结 2 618
悲哀的现实
悲哀的现实 2020-12-12 06:32

Hi I want to show 3 or 4 image in my view that are stored in sdcard the size of images is 1-2 MB approximately. My problem is when I use image in imageview then it throw ou

相关标签:
2条回答
  • 2020-12-12 07:27

    I have found solution of my problem there is my code :

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inTempStorage = new byte[24*1024];  
    options.inJustDecodeBounds = false;
    options.inSampleSize=32;     
    bmp1=BitmapFactory.decodeFile(filepath1,options);  
    Bitmap b1=ThumbnailUtils.extractThumbnail(bmp1,30, 30);  
    iv1.setImageBitmap(b);  
     if(bmp1!=null){  
       bmp1.recycle();
       }  
             bmp1=BitmapFactory.decodeFile(filepath1,options);
     Bitmap b2=ThumbnailUtils.extractThumbnail(bmp1,30, 30);  
     iv2.setImageBitmap(b2);  
    if(bmp1!=null){  
     bmp1.recycle();
     }
    

    similarly I have use it for four image view and set image without OOM Exception

    0 讨论(0)
  • 2020-12-12 07:33

    Create a BitmapFactory.Options and pass a value >1 in inSampleSize (preferably a power of 2) to scale the image down when loading it.

    0 讨论(0)
提交回复
热议问题