0

I have some images as bitmap,

I want to reduce the resolution of an image so it will be easier to work with (for computes on all the pixels).

  • I want to do it for images in different sizes.
  • I want that the size will stay the same (when I present it in the imageView)

How can i reduce the resolution and create a new bitmap to work with?

reut
  • 41
  • 7
  • To reduze a bitmap, you can to use the compress method with the jpg format: compress(Bitmap.CompressFormat.JPEG, HIGH_QUALITY_COMPRESS, yourFileToSaveIt) – Manuel Mato Jun 15 '20 at 13:09
  • @ManuelMato i wanted to use it, but i saw that then we save it into a file, and i want to use it again as a bitmap. there is a simple way to save it directly to bitmap? – reut Jun 15 '20 at 13:15
  • To reduce the resolution you have to scale the bitmap to a new resolution. Compressing makes no sense as it keeps resolution the same. It is unclear what you consider to be the size of a bitmap. It seems to me that whatever it would be it would change if you changed the resolution. – blackapps Jun 15 '20 at 14:20
  • @blackapps I have an image processing app, i preform on the images an algorithm that do calculates per pixel, in order to speed up the process i want to reduce the resolution of the images before applying the algorithm. is it more clear? – reut Jun 15 '20 at 15:19
  • No. As you dont have to tell why you want to reduce the resolution. – blackapps Jun 15 '20 at 16:48

1 Answers1

1

the problem solved using @blackapps comment and using the answer of @ariefbayu from this post https://stackoverflow.com/a/8268593/

Bitmap scaledBitmap = scaleDown(realImage, MAX_IMAGE_SIZE, true);

public static Bitmap scaleDown(Bitmap realImage, float maxImageSize,
        boolean filter) {
    float ratio = Math.min(
            (float) maxImageSize / realImage.getWidth(),
            (float) maxImageSize / realImage.getHeight());
    int width = Math.round((float) ratio * realImage.getWidth());
    int height = Math.round((float) ratio * realImage.getHeight());

    Bitmap newBitmap = Bitmap.createScaledBitmap(realImage, width,
            height, filter);
    return newBitmap;
}

now it works!

General Grievance
  • 4,555
  • 31
  • 31
  • 45
reut
  • 41
  • 7