24

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
Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
Tiago GP
  • 243
  • 1
  • 6
  • Does the error occur when taking pictures at all resolutions? Is it acceptable to take pictures at a lower resolution on the affected devices? – samgak Apr 15 '15 at 13:25
  • @samgak: Yes, it happens in all resolutions. No problem about the lower resolution, I'm already using it! Thanks. – Tiago GP Apr 16 '15 at 13:05
  • Did you try to start the preview after you set the parameters ? – Cynapsis Sep 01 '16 at 21:08

4 Answers4

1

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.

Racil Hilan
  • 24,690
  • 13
  • 50
  • 55
Rattata 2me
  • 37
  • 2
  • 5
0

This is not strongly related answer. I know.

But I'd like to say that Samsung 4.2.2 has many defective issues. It has ClipboardManager crash, ActionBar AppCompat crash, and so on.

Just filter it with simple if clause and save your life.

if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1 && Build.MANUFACTURER.toUpperCase().contains("SAMSUNG")){
    // ignore
}else{
    // your logic on the go
}
Youngjae
  • 24,352
  • 18
  • 113
  • 198
  • This is not the purpose of the question. We need to see a solution to the problem without going over the source of the problem. This is already done today, to prevent the error to occur, but is not ideal for us. – Julio Borges Apr 15 '15 at 13:12
  • @JulioBorges // why don't you think this model possibly have defective Camera driver or drop some packages in firmware? Samsung 4.2.2 really has issues. – Youngjae Apr 15 '15 at 13:16
  • @Youngjae: Samsung has its details, what you said is true, but the "if" clause only avoids the problem. I've done it before post here... Thanks anyway! – Tiago GP Apr 17 '15 at 11:48
0

are you again start a camera preview after taking a picture?

add this camera.startPreview();

Try this

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

    public void onPictureTaken(byte[] data, Camera camera) {
           camera.startPreview();
        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());
        } 
    }
};
Tiago GP
  • 243
  • 1
  • 6
Hardik
  • 17,179
  • 2
  • 35
  • 40
  • Firstly thank you! I tried that but didn't work. The picture is taken with no problem, the problem happens when I try to apply zoom, the screen freezes and no picture is captured and the biggest problem is that the app still alive and nothing is shown in LogCat. – Tiago GP Apr 22 '15 at 11:51
0

It's some issue with specific type of kernel.

Try this approach.

private static final String TAG = Test.class.getSimpleName();

private boolean isPreviewStarted;
private Camera camera;

Camera.PictureCallback photoCallback = new Camera.PictureCallback() {
    public void onPictureTaken(byte[] data, Camera camera) {

        // check if this needs to stop the preview
        if (deviceNeedsStopPreviewToShoot()) {
            stopPreview();
        }

        // save your image

        // restart preview if needed.
        startPreview();

    }
};

public void startPreview() {
    if (!isPreviewStarted && camera != null) {
        camera.startPreview();
        isPreviewStarted = true;
    }
}

public void stopPreview() {
    if (isPreviewStarted && camera != null) {
        camera.stopPreview();
        isPreviewStarted = false;
    }
}

public static boolean deviceNeedsStopPreviewToShoot() {
    String[] oldDevices = {"smdk4210", "aries"};
    boolean needs = Arrays.asList(oldDevices).contains(Build.BOARD);
    Log.e(TAG, "Device " + Build.BOARD + (needs ? " needs " : " doesn't need ") + "to stop preview");
    return needs;
}
MrOnyszko
  • 847
  • 9
  • 13