1

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.

Community
  • 1
  • 1
thekevshow
  • 774
  • 14
  • 36

2 Answers2

2

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?

Community
  • 1
  • 1
Emel Elias
  • 572
  • 7
  • 18
  • 1
    This did work as I had tried it earlier today, the post above this is also accurate since they are describing the same thing essentially. But you provide for useful code example off the bat so I have to give you the acceptance.Thank you. – thekevshow Jan 07 '15 at 02:23
  • the 4th line of code (Bitmap decoded = BitmapFactory...) helped me! thank you!! – Lazar Kukolj Jun 19 '16 at 02:43
1

Use Bitmap.compress(Bitmap.CompressFormat format, int quality, OutputStream stream) using Bitmap.CompressFormat.JPEG and set the quality to something less than 100. Play around with different quality values until you get the right balance between size and quality.

samgak
  • 23,944
  • 4
  • 60
  • 82
  • The code below is a more exampled approach for his post and he was first, so I had to give him acceptance, but the documentation you have and comments you said were helpful. Thank you. – thekevshow Jan 07 '15 at 02:23