Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android custom camera freeze after zoom

I have a custom camera that works fine in some devices. It works well on Samsung Galaxy Gran Duos (samsung-gt i9082, Android 4.2.2) but when I try to capture an image, that I zoomed in before, it freezes, no crash, the only way to get out is to press the back button. This happen only in the Samsung Galaxy Gran Duos.

The code that I used to take a picture:

    Camera.PictureCallback photoCallback = new Camera.PictureCallback() {

    public void onPictureTaken(byte[] data, Camera camera) {

        try {

        } catch (Exception e) {
            if (flePicture== null){
                Log.d("camera", "Error creating media file, check storage permissions: " +
                        e.getMessage());
                return;
            }
        }

        try {
            FileOutputStream fos = new FileOutputStream(flePicture);
            fos.write(data);
            fos.close();
        } catch (FileNotFoundException e) {
            Log.d("camera", "File not found: " + e.getMessage());
        } catch (IOException e) {
            Log.d("camera", "Error accessing file: " + e.getMessage());
        } 
    }
};

And the code used for the zoom in:

private void zoomIn() {
    if (pblnInPreview) {
        Camera.Parameters parameters = camCamera.getParameters();

        if ((parameters.getZoom() + 1) < parameters.getMaxZoom()) {
            parameters.setZoom(parameters.getZoom() + 1);
            camCamera.setParameters(parameters);
        }
    }
}

LogCat:

04-07 17:21:14.386: E/BrcmCamera(130): processControlBuffer: Corrupt stream error raised by camera - sensor communication failure
like image 288
Tiago GP Avatar asked Apr 08 '15 13:04

Tiago GP


1 Answers

I think you need to confirm that your camera supports zoom by using camera.isZoomSupported() then if it is supported you need to cancel auto focus with camera.cancelAutoFocus() to prevent image distorsions. But this will only work if your device actually supports zoom. If not you need to capture the hold image and zoom in after by using Bitmap.createBitmap an the section you want.

like image 153
Rattata 2me Avatar answered Oct 16 '22 17:10

Rattata 2me