dierre
dierre

Reputation: 7220

onPictureTaken method - getting data as a tiff?

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?

Upvotes: 2

Views: 830

Answers (1)

Eddy Talvala
Eddy Talvala

Reputation: 18137

No, TIFF is not supported directly. The most-compatible option to save a TIFF file is to decode the JPEG you receive from takePicture, by using BitmapFactory, and then use a TIFF library to save the bitmap to disk as a TIFF file.

Android's APIs do not support TIFF directly, so you'll have to find a 3rd-party library.

You might want to consider using PNG instead, since that's supported by the APIs directly; you could just call Bitmap.compress then.

Upvotes: 4

Related Questions