how to compress image for imageview in android

前端 未结 2 621
悲哀的现实
悲哀的现实 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

提交回复
热议问题