Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android save bitmap without compression

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.

like image 867
Dan Avatar asked Nov 10 '22 18:11

Dan


1 Answers

I have been read the google documentation and this is what I understand, but I'm not sure 100%:

The only way to get an uncompressed image from the android camera is saving it in SD card. Then, if you want to use it, get it from SD.

Indeed, it is not possible to pass an uncompressed image between activities by using intents due to intents can only "transport" objects of "small" size.

like image 128
Dan Avatar answered Nov 15 '22 06:11

Dan