app/src/main/java/com/yahala/ui/lazylist/ImageLoader.java
//decodes image and scales it to reduce memory consumption
decodes image and scales it to reduce memory consumption
decodes image and scales it to reduce memory consumption
private Bitmap decodeFile(File f) {
        try {
            BitmapFactory.Options o = new BitmapFactory.Options();
            o.inJustDecodeBounds = true;
            FileInputStream stream1 = new FileInputStream(f);
            BitmapFactory.decodeStream(stream1, null, o);
            stream1.close();
            final int REQUIRED_SIZE = OSUtilities.dp(150);
            int width_tmp = o.outWidth, height_tmp = o.outHeight;
            int scale = 1;  
            while (true) {
                if (width_tmp / 2 < REQUIRED_SIZE || height_tmp / 2 < REQUIRED_SIZE)
                    break;
                width_tmp /= 2;
                height_tmp /= 2;
                scale *= 2;
            }
            BitmapFactory.Options o2 = new BitmapFactory.Options();
            o2.inSampleSize = scale;
            FileInputStream stream2 = new FileInputStream(f);
            Bitmap bitmap = BitmapFactory.decodeStream(stream2, null, o2);
            stream2.close();
            return bitmap;
        } catch (FileNotFoundException e) {
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
private Bitmap decodeFile ( File f ) { try { BitmapFactory . Options o = new BitmapFactory . Options ( ) ; o . inJustDecodeBounds = true ; FileInputStream stream1 = new FileInputStream ( f ) ; BitmapFactory . decodeStream ( stream1 , null , o ) ; stream1 . close ( ) ; final int REQUIRED_SIZE = OSUtilities . dp ( 150 ) ; int width_tmp = o . outWidth , height_tmp = o . outHeight ; int scale = 1 ; while ( true ) { if ( width_tmp / 2 < REQUIRED_SIZE || height_tmp / 2 < REQUIRED_SIZE ) break ; width_tmp /= 2 ; height_tmp /= 2 ; scale *= 2 ; } BitmapFactory . Options o2 = new BitmapFactory . Options ( ) ; o2 . inSampleSize = scale ; FileInputStream stream2 = new FileInputStream ( f ) ; Bitmap bitmap = BitmapFactory . decodeStream ( stream2 , null , o2 ) ; stream2 . close ( ) ; return bitmap ; } catch ( FileNotFoundException e ) { } catch ( IOException e ) { e . printStackTrace ( ) ; } return null ; }
decodes image and scales it to reduce memory consumption
decodes image and scales it to reduce memory consumption
//decode image size //Find the correct scale value. It should be the power of 2. //int scale=(int)ImageSizeUtils.computeImageScale(new ImageSize(width_tmp, height_tmp), new ImageSize(200, 200), ViewScaleType.CROP,false); //decode with inSampleSize // Utilities.scaleCenterCrop(bitmap,100,100) ;