I need to build an app which take a picture or select an image from the gallery and I need to send it to the server with a size of 50kb.
Until now, I only find a code in which you can resize the width and height of the bitmap, but thanks to it, the bitmap loses quality.
public Bitmap getResizedBitmap(Bitmap image, int maxSize) {
int width = image.getWidth();
int height = image.getHeight();
float bitmapRatio = (float)width / (float) height;
if (bitmapRatio > 1) {
width = maxSize;
height = (int) (width / bitmapRatio);
} else {
height = maxSize;
width = (int) (height * bitmapRatio);
}
return Bitmap.createScaledBitmap(image, width, height, true);
}
Thanks in advance!