I'm working on android. I need to save a bitmap without quality lost.
I have tried it using compress()
method of Bitmap, setting quality to 100. This not works for me, the bitmap loses too much quality. I have tested with JPEG and PNG formats.
I have tested to copy the bitmap to a ByteBuffer
, then extract the byte[]
and saving it using a FileOutputStream
. In this case, I can't display images saved using this way, I only see a blank page.
My question is, is there any way to save a bitmap in SD card without compression?
EDIT: here part of my code
public class MainActivity extends ActionBarActivity {
[...]
@Override
protected void onActivityResult(int reqCode, int resCode, Intent handler){
super.onActivityResult(reqCode, resCode, handler);
if(reqCode == CAPTURE_IDENTIFIER && resCode == Activity.RESULT_OK){
// THis is that I have tested.
// Object o = handler.getData();
// Object o2 = handler.getExtras().getParcelable("data");
// Object o3 = handler.getExtras().get("data");
// Object o4 = handler.getParcelableExtra("data");
//
prepareCapture();
startActivityForResult(cameraHandler, CAPTURE_IDENTIFIER);
}
}
private void initCamera(){
cameraHandler = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraHandler.putExtra("return-data", true);
}
private void prepareCapture(){
currentPhotoName = getNextImageIdentifier() + IMG_BASE_NAME;
File image = new File(capturesFolder, currentPhotoName);
Uri uriImage = Uri.fromFile(image);
cameraHandler.putExtra(MediaStore.EXTRA_OUTPUT, uriImage);
}
}
THe exception i have detected is: RuntimeException: failure delivering result ResultInfo [...] NullPointerException
EDIT2: What I have to actually do:
I have to take a photo with the camera, then before save it, I have to process it. After that, i have to save it in SD card. But it's very important the image quality, I can't save it with low quality, or not too low quality at least.
Bitmap
or how you are determining "lower quality". - CommonsWare