tags:

views:

146

answers:

1

I have an app which uses the Camera, sending the preview to a SurfaceHolder. Everything works fine on the HTC Desire that I have been developing on, but when I run it on a Samsung Galaxy S the image from the preview is rotated 90 degrees.

The code attempts to match the best Size returned from the parameters.getSupportedPreviewSizes(), with the width and height of the Surface (as passed into SurfaceChanged as width and height).

(the image is also rotated on the Galaxy when an image is taken from the app).

Has anyone else had problems with the preview on the Galaxy? Or better yet got around the problems?

A: 

Yes, had exactly the same, see: http://stackoverflow.com/questions/3213741/camera-preview-on-android-strange-on-samsung-galaxy-s

In order to have the final image in the right rotation as well as the cam preview, I do a manual rotation on the captured image like this

..
    final Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    matrix.preRotate(degrees);

    // recreate the new Bitmap
    final Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, x, y, width,
            height, matrix, true);
..
Mathias Lin
Thanks for this, how did you test if the rotation was needed or not?
Lyndon
I entirely removed/didn't use the p.set("orientation", "portrait");p.set("rotation", 90); parameters, and therefore in all cases rotate the image. This way it should work on all devices. But I'm not sure, I couldn't test much lately. In my case, I had the problems on a Samsung Galaxy S that didn't support these params.I don't know how to check generally, you should need a list of models that support those params and then check the device model - that can be read via API. But I think maybe the first approach to just avoid these params might be more safe.
Mathias Lin
I wasn't actually using those params at all, so it'll certainly be easy to avoid them.
Lyndon
Managed to go back and have a look at this, and I cant see how to implement your suggestion, did you manage to catch the preview image, convert it into a bitmap, then send it back to the surfaceview? Or does your suggestion only work for _photos_ taken with the camera (rather than the live preview)?
Lyndon
rotating the captured picture taken manually, not the preview itself. But the issue with the preview, which I had (screenshots in the link I posted) were gone after removing the mentioned parameters. Can you post your code where you set all the camera settings, etc.?
Mathias Lin
I've actually removed the entire set parameters section. simply opening the camera, then starting preview. I've been told that it doesn't work an anything that isn't an HTC phone.Whats annoying is that all of the other information on the internet seems to be telling me to put those very parameters in!
Lyndon