0

When i capture an image from the camera (from the device home screen) and check the image size on the SD card, it shows between 300-500 Kb.

But when i capture an image in my Application using the Camera Intent, and save it on SD card(in a new folder) it shows image size between 5-10 Kb.

This is the code i am using to save the Image on the SD card after taking the picture in the onActivityResult:

Bitmap bit = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream bao = new ByteArrayOutputStream();
bit.compress(Bitmap.CompressFormat.JPEG, 100, bao);
byte[] ba = bao.toByteArray();
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "My - Images");
File f = new File(imagesFolder, "test.jpg");
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(ba);
fo.flush();
fo.close();

how to save it as the original sized image(300-500 Kb)?

and is there a way to get the image size before i save it on the SD card??

Thank You

Archie.bpgc
  • 23,812
  • 38
  • 150
  • 226
  • yeah. now the image size has increased to 35 KB but the height and width remains(150 x 200) the same. moreover when i take the picture from camera it gives an image of 300-500 KB size and the size is 800 x 800 around – Archie.bpgc Sep 25 '12 at 10:51
  • its actually 1600 x 1200 – Archie.bpgc Sep 25 '12 at 10:58

3 Answers3

1

You are using the following to compress the bitmap object you receive:

bit.compress(Bitmap.CompressFormat.JPEG, 100, bao);

That is the reason your bitmap is being stored in a compressed format.

Also, you can use bit.getHeight() and bit.getWidth() to get the dimensions of your bitmap. You can use bit.getByteCount() to get the actual size of your bitmap

zeiger
  • 700
  • 5
  • 16
  • but i am using 100. Doesn't that mean i am asking for 100% quality or the original quality? because i tried removing this line, and all i get is a 0 sized image since i am not using any format. which format should i use to get the original quality?? – Archie.bpgc Sep 25 '12 at 09:05
  • Oh my mistake, I didn't know 100 is the quality % that you specify. In that case, 100 should be max. quality. I will try to look into my code as I have done something similar as well. – zeiger Sep 25 '12 at 09:20
  • and couldn't find any method like bit.getByteCount(); – Archie.bpgc Sep 25 '12 at 09:35
  • Here it is: http://developer.android.com/reference/android/graphics/Bitmap.html#getByteCount() – zeiger Sep 25 '12 at 10:12
  • Okay. Actually that is added in API 12. I am using API 10, so couldn't find :) – Archie.bpgc Sep 25 '12 at 10:38
1

Check the answer that is accepted here, hope it may work for you

Android Camera Intent: how to get full sized photo?

Community
  • 1
  • 1
Mohit Verma
  • 3,025
  • 1
  • 20
  • 36
  • yeah i already read this. Here the solution say "you only get full sized image once you save it in a temp file". in my app i am storing them on the SD card and then checking the size – Archie.bpgc Sep 25 '12 at 11:54
0

Firstly try to find out the size of the picture using the code below

Camera mCamera = null;
Camera.Parameters camParams = mCamera.getParameters();
Size camSize = camParams.getPictureSize(); 

If the picture size you get is 5-10 KB, then there is nothing wrong with your code, you may have to re-visit your camera parameters to see what quality you have set.

Royston Pinto
  • 6,681
  • 2
  • 28
  • 46