0

I’ve looked through a lot of questions regarding image quality and tried a bunch of them, but I can’t seem to find a solution to this issue. I am trying to scale an image down from my phone gallery and, while it resizes to the correct dimensions, the image quality drops. Take a look at this image that I scaled down by hand in Apple Preview:

enter image description here

vs what my function is doing

enter image description here

Here’s my function below. My intention with this function was to scale the image down proportionally to as close to the desired width as I can get:

public static Bitmap resize(String filepath, float desired_width)
{
    float percent = getPercent(filepath, desired_width);
    int newWidth = Math.round(getImageWidth(filepath) * percent);
    int newHeight = Math.round(getImageHeight(filepath) * percent);
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = false;
    options.inScaled = false;
    Bitmap myBitmap = BitmapFactory.decodeFile(filepath, options);
    Bitmap bmp = Bitmap.createScaledBitmap(myBitmap, newWidth, newHeight, false);
    return bmp;

}

I’ve tried removing the “options” argument decodeFile, but the image looks the same. What am I doing wrong?

Hitesh Bhalala
  • 2,872
  • 23
  • 40
pnus
  • 187
  • 1
  • 14
  • Did you try `Bitmap bmp = Bitmap.createScaledBitmap(myBitmap, newWidth, newHeight, true)`? – Fabin Paul Dec 08 '15 at 03:57
  • check answer here -- http://stackoverflow.com/questions/8327846/how-to-resize-a-bitmap-eficiently-and-with-out-losing-quality-in-android – Tasos Dec 08 '15 at 04:00
  • @FabinPaul, I tried that. Same result. This is driving me nuts. – pnus Dec 08 '15 at 04:20
  • check if this answer works out [link](http://stackoverflow.com/questions/4821488/bad-image-quality-after-resizing-scaling-bitmap#answer-7468636) – Fabin Paul Dec 08 '15 at 04:27

0 Answers0