Search code examples
androidandroid-imageimage-compression

Android Image Compression Without Res Change


I am looking for a solution that I found here for IOS for an android application. I have developed IOS applications and was just wondering if anyone had some insight on how to achieve this similar goal in android.

I am trying to just compress the image before uploading it to the server. I do not need the resolution to go down, and 200 kb or up to 400 kb should be fine and keep things looking alright for a phone. If anyone can take a look as at least give me a direction. I figured I would ask this before diving into some more complicated ways to do it that I have read into. If there was something as easy as it was in IOS then that would be better.

Thank you.


Solution

  • try

    Bitmap original = BitmapFactory.decodeStream(getAssets().open("1024x768.jpg"));
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    original.compress(Bitmap.CompressFormat.PNG, 100, out);
    Bitmap decoded = BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()));
    

    from How to make Bitmap compress without change the bitmap size?