问题
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
回答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
回答2:
Check the answer that is accepted here, hope it may work for you
Android Camera Intent: how to get full sized photo?
回答3:
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.
来源:https://stackoverflow.com/questions/12579084/android-save-image-on-sd-card-with-its-original-size