I\'m developing a camera app basically as part of a messaging app to attach images etc. The app needs to work for >= SDK 2.2 and:
I can\'t use the defau
Check out this posting on how to switch the QR scanner to be portrait: http://code.google.com/p/zxing/issues/detail?id=178. I don't know if it relates to your swapping of the picture to be portrait but maybe it provides some guidance. Comment #11 seems to be the most helpful. (I am not endorsing that the QR app code be ripped off from Sean Owen).
I suspect your problem is at a couple different levels.
Sensor Mount
First, the camera sensor is mounted different on every device. Google has boiler plate code for getting that orientation and setting the correct rotational value to correct it here and it is good down to API 8.
AR Correction
The second issue is obviously that the preview frames aren't the same aspect ratio as the screen. You can use this post to solve that. The surfaceview dimensions have no relation to the best preview size, those values do not have to match - in fact, that your AR is messed up proves that they don't match.
Preview Frame Size != Picture Size
Finally, when you take a picture using takePicture, the size of the picture is completely independent of the size of your preview frame. Use the following to query and set the preview frame size: setPreviewSize() / getSupportedPreviewSizes()
Use the following to query and set the picture size (from takePicture()): getSupportedPictureSizes() / setPictureSize()
Some devices you may get lucky on and the defaults for pictures and preview frames will be the same. This is not the case on all devices.
Finally, if you want to display the taken picture, you may need to do AR correction on it as well if it's not the same size as your SurfaceView. Alternatively you could draw it to an ImageView and use ScaleType.CENTER_INSIDE to preserve the aspect ratio.
Android camera system is a mess. And beind soldered to motherboard, camera chip is not going to like portait application - all the callbacks spill out data in camera orientation (buffer you receive is actually shared memory piece with native camera app) - if you like to display it while your application is in portait mode, you will have to flip this data over xy
.
Instead of showing image on the surface view used by camera, I would overlay it with transparent ImageView
and draw my bitmap there.
You may (hopefully) find some inspiration in out javaocr project where android deamon work in portrait mode and draw bitmaps over live preview. (please checkout from git
, as it is being released now and I'm struggling with git and maven, see demos directory)