4

What is the image format in the Preview Screen when Camera is enable?

Is it RGB? Or YUV? Or others?

So when I take a photo, I basically ask Andriod to convert whatever on screen from YUV format to JPEG?

And when I record a video, Android convert that format to mp4?

CompEng
  • 7,161
  • 16
  • 68
  • 122
n179911
  • 19,547
  • 46
  • 120
  • 162

2 Answers2

2

It is NV21. See the online document. To save the data to JPEG, you can do this:

            YuvImage im = new YuvImage(preview_data, ImageFormat.NV21, preview_width, preview_height, null);
            int quality = 90;
            Rect rect = new Rect(0, 0, preview_width, preview_height);
            FileOutputStream output = new FileOutputStream("/sdcard/test.jpg");
            im.compressToJpeg(rect, quality, output);
            output.flush();
            output.close();
yushulx
  • 11,695
  • 8
  • 37
  • 64
0

There is a alternate way, how i am doing the same, may help you: For taking picture:

  1. init camera and set onPictureTaken method.

    Camera camera = Camera.open(); if(camera != null) { camera.takePicture(null, null, jpeg); }

now implement Camera.PictureCallback with name "jpeg", in which you will get captured image in JPEG format

  1. set desired image format in onSurfaceChanged method

    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { if (holder != null && camera != null) { camera.stopPreview(); Camera.Parameters parameters = camera.getParameters(); parameters.setPictureFormat(PixelFormat.JPEG); camera.setParameters(parameters); camera.setPreviewDisplay(holder); camera.startPreview(); } }

For Recording video

  1. init camera.

    Camera camera = Camera.open();

  2. init Media recorder and set desired video format on recorder

if ( camera != null) { try{ camera.stopPreview();

    MediaRecorder recorder = new MediaRecorder();
    recorder.setCamera(camera);
   recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    recorder.prepare();

}

Source: for Take picture, for Record video

Community
  • 1
  • 1
swiftBoy
  • 35,607
  • 26
  • 136
  • 135