Android or Java. Reduce image size without (with minimal) loss of quality

I take photos in a resolution of 1440 x 1080. I use the following code to expand the image if necessary, crop the square, and reduce it to 1000x1000. After all these operations, the quality of the photo when zoomed in is not very good, despite the fact that the phone's camera is very good (and the native camera takes great photos, but there is a resolution of 4000x3000).

Is it true that there are different algorithms and approaches to image compression/reduction? standard android tools compress and reduce images in a way that is not optimal?

Is it possible to better compress and reduce photos on android?

Bitmap bm = BitmapFactory.decodeByteArray((byte[]) data, 0, data.length);

Matrix matrix = new Matrix();
matrix.postRotate(getRotateAngle());

int width = camera.getParameters().getPictureSize().width;
int height = camera.getParameters().getPictureSize().height;
int croppedWidth = width > height ? height : width;

bm = Bitmap.createBitmap(bm, 0, 0, croppedWidth, croppedWidth, matrix, true);
if (croppedWidth >= 1000) {
   bm = Bitmap.createScaledBitmap(bm, 1000, 1000, false);
} else {
   bm = Bitmap.createScaledBitmap(bm, croppedWidth, croppedWidth, false);
}

File outputDir = context.getCacheDir(); 
File outputFile = File.createTempFile("prefix", "extension", outputDir);

FileOutputStream fos = new FileOutputStream(outFile);

ByteArrayOutputStream stream = new ByteArrayOutputStream();

img.compress(Bitmap.CompressFormat.JPEG, 100, stream); 

fos.write(stream.toByteArray());
fos.close();
Author: Евгений, 2018-10-10

1 answers

I took an example of compression from the English-language StackOverflow, with a quick glance at the comment to the fourth argument "filter boolean: true if the source should be filtered." from which I did not understand anything, decided not to touch it and forgot about it, I thought the reason was not this.

Bitmap.createScaledBitmap(bm, 1000, 1000, false);

A long googling led to this answer What does the filter parameter to createScaledBitmap do?

To expand on Karan's answer: As a general rule you won't see any difference if you're scaling your image down, but you will if you're scaling it up.

Passing filter = false will result in a blocky, pixellated image.

Passing filter = true will give you smoother edges.

However, as EIYeante pointed out in the comments, you might still see a difference. This is their example image.

Replacing false with true gave me a satisfactory result. When set to false after scaling the edges of the shapes/lines they were angular/scratchy/rough. If the value is true, the lines are smooth, and the result is much better.

Bitmap.createScaledBitmap(bm, 1000, 1000, true);

 2
Author: Евгений, 2018-10-11 12:11:30