0

I am developing an application which loads images from local device storage. I used compression technique code:

FileOutputStream fo = new FileOutputStream(file);
picture.compress(Bitmap.CompressFormat.JPEG, 90, fo);
fo.flush();
fo.close();

where picture is a bitmap. This shows a low quality unreadable image.

Is there any efficient compression technique. Also, how does android gallery show thumbnail images which are readable and of smaller file size?

2 Answers2

1

Hope it will help you

Picasso.with(context)
            .load(imageUri) // will come from gallery
            .resize(imageWidth, imageWidth).centerInside()
            .into(imageview);

I have done this

    public static final int GRID_PADDING = 8; // in dp
    public static final int NUM_OF_COLUMNS  = 3; 
    Resources r = getResources();
        float padding =   TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,GRID_PADDING,r.getDisplayMetrics());
imageWidth = (int) ((getScreenWidth()) - ((NUM_OF_COLUMNS + 1) * padding)) /   NUM_OF_COLUMNS);
Nisarg
  • 1,358
  • 14
  • 30
1

Solved it using ThumbnailUtils:

   Bitmap picture = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(_path_to_your_file), FINAL_WIDTH, FINAL_HEIGHT);

Image size is reduced much