So I was reading many tutorials on how to get an image preview and then save it.
The usual tutorial involves using SurfaceHolder
and SurfaceView
with a PictureCallback
.
As it appears on the documentation this is the signature for
public abstract void onPictureTaken (byte[] data, Camera camera)
Usually to save the image you can do something like
/** Handles data for jpeg picture */
PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
FileOutputStream outStream = null;
try {
// write to local sandbox file system
// outStream =
// CameraDemo.this.openFileOutput(String.format("%d.jpg",
// System.currentTimeMillis()), 0);
// Or write to sdcard
outStream = new FileOutputStream(String.format(
"/sdcard/%d.jpg", System.currentTimeMillis()));
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");
}
};
but I'm not interested in saving a jpeg. I want to save a tiff image. Reading the documentation I've found a really general comment on data
format:
Called when image data is available after a picture is taken. The format of the data depends on the context of the callback and Camera.Parameters settings.
So I clicked on Camera.Parameters but I didn't find anything useful.
Is there a way to save the bytes as tiff? Am I doing something wrong?