Home > Android > Android Camera Preview Sizing

Android Camera Preview Sizing

February 1st, 2011

A quick “from the trenches” post. Recently I’ve been digging in to the Android camera a bit. The Android SDK samples have an example of how to wire up a live preview from the camera on the device directly to a Surface view. Unfortunately, this fails miserably on my Samsung Captivate with a repeating error similar to the following.

07-04 12:23:45.101: ERROR/copybit(2230): Error in VIDIOC_STREAMON
07-04 12:23:45.101: ERROR/copybit(2230): Fail : v4l2_stream_on()
07-04 12:23:45.106: ERROR/copybit(2230): stretch_copybit::sec_stretch fail : ret=-5

This had me stymied for a bit until I took a look at the awesome zxing (Zebra Crossing) project where I stumbled on to a solution for this problem. (All credit goes to their developers). The code in their CameraManager class and CameraConfigurationManager class goes through a number of gyrations to pick an appropriate preview size. Using that code allows the Captivate to properly render a live preview.

Thanks to the zxing crew for this little tidbit, as I’m not sure I would have figured this one out on my own.

Categories: Android Tags:
Comments are closed.