GetSupportedPreviewSize returns reverse width and height

android, android-camera, preview

Solution

The proper way to think about the camera is in landscape mode, this means that when you are thinking about it in portrait mode, the width and height feel "flipped".

The `getBestPreviewSize( w, h, p )` function is simply a wrapper around the `getSupportedPreviewSizes()` function of `Camera.Parameters`, so the width and height passed in will not change the result of the bestPreviewSize function.

Problem

I'm using a DroidX to develop an app that uses the camera preview image. The code I'm using is found in numerous places on the web but I noticed that the common method "getBestPreviewSize(width,height,camera.parameters)" is returning such a small size that the standard decodeYUV420SP method fails with null pointer exception. Some debugging reveals the supportedPreviewSizes for my DroidX are: - 144h x 176w - 240h x 320w - 288h x 352w - 480h x 640w - 480h x 720w - 448h x 800w - 720h x 1280w Note that the values of height and width give a landscape perspective. This does not change with camera orientation. The width and height of the surface passed to `getBestSupportedPreviewSizes` is 480w x 778h. When I pass the camera.parameters to `getBestSupportedPreviewSizes()` it returns a 288 x 352 size. Here is the calling code - I apologize if the format is off but here is goes: ``` if (!cameraConfigured) { Camera.Parameters parameters=camera.getParameters(); Camera.Size size=getBestPreviewSize(pwidth, pheight, parameters); if (size!=null) { parameters.setPreviewSize(size.width, size.height); camera.setParameters(parameters); cameraConfigured=true; } } ``` `pwidth` and `pheight` are from the `surfaceChanged` callback's width and height parameters. I've tried camera.setDisplayOrientation(90); in onResume(). I've also put orientation("Portrait") in the the manifest - none of the 4 combinations of these attempts seem to change this behavior. My thoughts are to simply reverse them, but it feels wrong on so many levels. Since this freely available code seems to have proven itself in so many other examples, I'm obviously approaching it wrong. Can anyone supply some insight to this behavior? Thanks in advance.

Original source