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:
vs what my function is doing
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?