1

I want to resize an image to a smaller image like thumbnail. I have used following options

Bitmap imageBitmap = Bitmap.createScaledBitmap(mBitmap, 200, 700, false);

and

ThumbnailUtils.extractThumbnail()

Both of these options cut parts of images. So they don't look good. I just want to reduce image dimensions and don't want to loose image content.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
hard coder
  • 5,449
  • 6
  • 36
  • 61
  • 1
    Possible duplicate of [How to resize a bitmap eficiently and with out losing quality in android](https://stackoverflow.com/questions/8327846/how-to-resize-a-bitmap-eficiently-and-with-out-losing-quality-in-android) – Manohar Dec 06 '17 at 07:10
  • https://stackoverflow.com/questions/47627727/cropping-image-by-setting-height-dynamically/47627812#47627812 – Jackey kabra Dec 06 '17 at 07:13
  • Possible duplicate of [Decrease image size without losing its quality in android](https://stackoverflow.com/questions/28424942/decrease-image-size-without-losing-its-quality-in-android) – ADM Dec 06 '17 at 07:17

3 Answers3

1

you have to try like this

public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth)
{
    int width = bm.getWidth();
    int height = bm.getHeight();
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;
    // create a matrix for the manipulation
    Matrix matrix = new Matrix();
    // resize the bit map
    matrix.postScale(scaleWidth, scaleHeight);
    // recreate the new Bitmap
    Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
    return resizedBitmap;
}
Raja
  • 2,775
  • 2
  • 19
  • 31
1
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    Bitmap bitmap = BitmapFactory.decodeFile(filepath,bmOptions);

   //Part 1 :withcompression Sacle image 200 pixels x 700 pixels this size you can customize as per your requirement

   Bitmap withCompressed = Bitmap.createScaledBitmap(bitmap,200,700,true);
Dilip
  • 2,622
  • 1
  • 20
  • 27
0

If you want to resize an image without losing quality and images are from drawable/mipmap then you should try pngquant.

https://pngquant.org/

Nimisha V
  • 461
  • 4
  • 12