3

After hours of investigation and combing through various tutorials and tips, I have run out of options and decided to post my question.

What I am seeing is that when the user selects an Image from the Photo Gallery and I upload that image to my server, the size of the image is drastically reduced.

I remember seeing a tip somewhere that the standard behavior when selecting from the gallery is a thumbnail image instead of the full image. Is that true? Here is my relevant code:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
intent.setType("image/*");
intent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri());             
startActivityForResult(intent, PICK_FROM_FILE);

Then, I retrieve the file that I created and do this (is this where I am losing the quality???):

Bitmap bitmap = BitmapFactory.decodeStream(new FileInputStream(tempFile1));

Then, here is my logic to convert it to a ByteArray:

Bitmap bmp = BitmapFactory.decodeFile(fileString);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte [] ba = stream.toByteArray();

To take this one step further, I would like to have the ability to crop the image and keep the size proportional to the original size. For example, if the original size of the image is 2000x2000 and the user crops the image in half vertically, I would like to have the end result be 1000x1000. Any insight or tips would be greatly appreciated. Thank you.

majors44
  • 123
  • 1
  • 8

1 Answers1

0

Try Using

**

bmp.compress(Bitmap.CompressFormat.PNG, 100, stream)

**;

also read the below given link to understand the difference. PNG vs. GIF vs. JPEG vs. SVG - When best to use?

Community
  • 1
  • 1
AndoAiron
  • 674
  • 5
  • 19