-1

I've tried in my android application to take pictures without using native camera application.I want to save the captured picture in a separate folder.I get the byte array of the image from onPictureTaken(). I want to save this picture into a separate folder with a file name.How's it possible. My code snippet is as follows:

    mCamera.mCameraInstance.takePicture(null, null,
            new Camera.PictureCallback() {

                @Override
                public void onPictureTaken(byte[] data, final Camera camera) {

         byte[] capturedBytes=data;



                    }

2 Answers2

2

This is what i'm using. The takePicture uses the jpegCallback. The jpegCallback saves the image to the sdcard, then restarts the preview.

preview.camera.takePicture(null, null, jpegCallback);


PictureCallback jpegCallback = new PictureCallback() { // <8>
  public void onPictureTaken(byte[] data, Camera camera) {
    FileOutputStream outStream = null;
    try {
      // Write to SD Card
      outStream = new FileOutputStream(String.format("/sdcard/before.jpg")); 
      outStream.write(data);
      outStream.close();
    } catch (FileNotFoundException e) { // <10>
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
    }
    camera.startPreview();
  }
};
Fred F
  • 1,027
  • 1
  • 9
  • 18
0

Check out that: https://stackoverflow.com/a/7982964/944070

also do not forget manifest permission WRITE_EXTERNAL_STORAGE

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Community
  • 1
  • 1
madlymad
  • 6,367
  • 6
  • 37
  • 68