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 default Android Camera as much as I’d love to because:
-
The nature of the app dictates that the image should not be saved to disk ever and some OEMs (Samsung) love to do this without giving you a choice.
-
I can’t call an intent that any other camera app can intercept because then that app could save the image.
My current problem is dealing with the fact that the Android camera apparently hates being in portrait orientation. Specifically, after some digging I’m monitoring the display and, on rotation, calling setDisplayOrientation(90). This works but the surfaceview dimensions need to be altered also and this must be done within supported dimensions or the parameter setting crashes the app.
I’m doing this with another SO snippet I found here (the getBestPreviewSize() method) but it has one glaring problem that I can’t believe I haven’t found anyone else having.
Part of the takePicture lifecycle involves calling the PostView picture callback. This is what shows the still image of the current paused SurfaceView image that will be returned via byteArray to the raw and/or jpeg callback. My problem is, this image is still skewed on a handful of seemingly random test devices! So the behavior is a user sees a dynamic camera image in perfect 4:3 aspect ratio until they take the picture and the image they are presented with is squished. Note that the byte array itself is correct and when I construct the Bitmap at the messaging end point it shows up fine but this is still a problem.
I can’t see how I can alter the still image display at this point. Can anyone help me with this?
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
ImageViewand 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)