tags:

views:

1044

answers:

3

Hi,

I would like to save a preview frame as a jpeg image.

I have tried to write the following code:

public void onPreviewFrame(byte[] _data, Camera _camera)
  {
   if(settings.isRecording())
   {
    Camera.Parameters params = _camera.getParameters();
    params.setPictureFormat(PixelFormat.JPEG);
    _camera.setParameters(params);
    String path = "ImageDir" + frameCount;
    fileRW.setPath(path);
    fileRW.WriteToFile(_data);
    frameCount++;
   }
  }

but it's not possible to open a saved file as a jpeg image. Does anyone know how to save preview frames as jpeg images?

Thanks

A: 

_data probably isn't in JPEG format. Did you call Camera.Parameters.setPreviewFormat(PixelFormat.JPEG) before calling start preview?

hacken
it doesn't solve the problem
niko
What format does the camera parameters say the image is in?
hacken
A: 

I set the PreviewFormat with Camera.Parameters.setPreviewFormat(PixelFormat.JPEG) before preview,but it seems that it can't really set the previewformat...... By the way, the default format of the preview is YCbCr_420_SP....

A: 

You have to convert it manually, there are some examples on the android-developers list if you browse the archive - mostly dealing with the format (luminance/chrominance,etc) conversion, then writing the image to a bitmap, then saving to a file.

It's all a bit of a pain really.

piemmm