udakarajd
udakarajd

Reputation: 114

is there a way to derectly save camera pictures in NV21 format android

I want to know a way to save a camera picture directly in yuv(NV21) format (On SD card or Buffer) for processing. I already can save it in jpeg format, but i think converting it to NV21 is slower. In my application, showing the taken picture back to the user is unnecessary. here is the part where i save the picture as jpeg. obviously I am missing something here.

    ShutterCallback shutterCallback = new ShutterCallback() {
        public void onShutter() {
            Log.d(TAG, "onShutter'd");
        }
    };

    /** Handles data for raw picture */
    PictureCallback rawCallback = new PictureCallback() {
        public void onPictureTaken(byte[] data, Camera camera) {
            Log.d(TAG, "onPictureTaken - raw");
        }
    };

    /** Handles data for jpeg picture */
    PictureCallback jpegCallback = new PictureCallback() {
        public void onPictureTaken(byte[] data, Camera camera) {
            FileOutputStream outStream = null;
            try {

                //create the directory 
                String state = Environment.getExternalStorageDirectory().getPath()+"/CamOverlay";

                File folder = new File(state);
                boolean success = true;
                if (!folder.exists()) {
                    success = folder.mkdirs();
                }
                if(!success)
                    Log.d(TAG,"directory creation failed");


                // Or write to sdcard
                String name=String.format("/%d.", System.currentTimeMillis());
                outStream = new FileOutputStream(state+name+"jpg");

                outStream.write(data);

                outStream.close();

                Log.d(TAG, "onPictureTaken - wrote bytes: " + data.length);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
            }
            Log.d(TAG, "onPictureTaken - jpeg");

            safeToTakePicture=true;
            preview.camera.startPreview();
        }
    };

}

and here is the camera setting..

myParameters.setPictureFormat(ImageFormat.YV12);

setting this to below didn't work

myParameters.setPictureFormat(ImageFormat.NV21);

I'm new to android, this code is created using several examples on the internet. therefore if there is a mistake, please point it out.thanks in advanced.

Upvotes: 2

Views: 1393

Answers (0)

Related Questions