Mayank Thakur
Mayank Thakur

Reputation: 61

How to take a Picture using CameraKit?

I've been building a project that uses the CameraKit by Flurge, and I have a rather annoying issue. I don't actually know how to take a picture. I have a shutter button that when pressed is supposed to activate an OnPicturetaken Listener, but I don't know if it works or not, or whether it is being saved or not. When I click the shutter button on my phone, the logcat returns the dimensions of the picture, which is 13 Mp, but it doesn't save it.

This is the code that runs when the shutter button is pressed:

cameraView.captureImage();
cameraView.setCameraListener(new CameraListener() {
    @Override
    public void onPictureTaken(byte[] picture) {
        super.onPictureTaken(picture);

        Bitmap result = BitmapFactory.decodeByteArray(picture, 0, picture.length);
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        result.compress(Bitmap.CompressFormat.JPEG, 40, stream);
    }
});

I tried to set the JPEG quality to 40 to decrease the freeze of the app as it processes the image, but it doesn't help at all. The only output I get is in the logcat of the full resolution of the image, which is 13Mp.

Upvotes: 0

Views: 1981

Answers (2)

RHAZ
RHAZ

Reputation: 13

You need to call captureImage(); below the listener.

It looks like you are capturing an image before the listener is even set up. It should look like this.

cameraView.setCameraListener(new CameraListener() {
    @Override
    public void onPictureTaken(byte[] picture) {
        super.onPictureTaken(picture);

            Bitmap result = BitmapFactory.decodeByteArray(picture, 0,picture.length);
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            result.compress(Bitmap.CompressFormat.JPEG, 40, stream);

    }
});
cameraView.captureImage();

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1006539

whether it is being saved or not

If by "saved", you mean being written to disk or the network, you do not have any code for doing this in your question.

this is the code that runs when the shutter button is pressed:

If you want to save the image to the disk, fork a thread and write the bytes to a FileOutputStream, where the FileOutputStream points to wherever you want the image to be stored on internal storage or external storage. You do not need to decode the byte[]; it is already in JPEG format, so you can just write the bytes.

Upvotes: 2

Related Questions