• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Issues with Camera Preview

ophanin

Newbie
Hi all,

I am currently trying to develop on a Motorola Droid for a project, and I am trying to use the camera preview and its callback for taking the images directly from the feed.

This has not been as straightforward as I thought it should be, mostly due to the preview being in the YUVSP420 (at least, I believe so) format. After searching through a lot of the developer resources, I found some conversion code posted by (who I believe was) an Android Engineer, which would convert the raw image to a RGB, but I cannot seem to get this to work correctly. I get a very warped image, with the colors very far off. I think this may be due to using the wrong resolution for the conversion.

My question here, mostly, is does anyone have any suggestions? Also, is there an easy way to find what resolution an image is from the previewCallback? I can post more specific code and values, if they are necessary, I just do not have it running right now.
 
What are you trying to accomplish with the callback? It seems like using camera.takePicture() would be a better choice if you're working with the image data in most cases. That'd let you specify the jpeg callback, which gives you a much more easily used format.
 
My application is more real time. I first investigated taking the picture itself, but the lag will be a bit much for me to handle (in in the end, the plan is to make a disability assistance program for people with limited vision).

So, in essence, I looked into picture taking, but it wouldn't serve my needs.
 
Would it help to call setPreviewFormat(ImageFormat.JPEG) to work with JPEG data instead of the default NV21? (You could also try ImageFormat.RGB_565)
 
Check out the Camera.Parameters class (acquire via Camera.getParameters())
You can check/set preview (including callback) sizes etc
 
The preview format is only available in FroYo, but I was able to find a workaround from a post by a Google engineer. Hopefully, when I finally get FroYo on my dev phone, it'll be a much quicker process! :)
 
Hi All,
Am a newbie. I am able to get the preview frames supposedly in YCrDr420 format. I am not sure despite setting setpreviewformat as JPEG, the call back byte[] will be JPEG or YCrDr420.

Now, I neeed to convert this in to JPEG? Any help is appreciated.Thanks
 
They come normally in the YUV420 format, that's just how the camera takes them. I am unsure of how it handles it when the format is changed (I haven't been able to try it in 2.2).

The easiest way to find out if it's coming is probably to just use the BitmapFactory.decodeByteArray method. Since it's (at least should be) coming in as JPEG, the BitmapFactory should recognize it and convert it.
 
Thanks for the quick reply. my code is as follows::

mCamera.setPreviewCallback(new PreviewCallback()
{
public void onPreviewFrame(byte[] _data, Camera _camera)
{

Bitmap bmp = BitmapFactory.decodeByteArray(_data,0, _data.length);

imv = (ImageView)findViewById(R.id.ImageView01);
imv.setImageBitmap(bmp);
System.out.println("bmp painted ");


}
});


} catch (Exception exception) {
mCamera.release();
mCamera = null;
// TODO: add more exception handling logic here
}
}

i am getting the bitmap, and i need to set it in Image view. How do i accomplish this?
thanks.
 
Can do something like this, with an ImageView (ImageView01) in your layout

ImageView image = (ImageView) findViewById(R.id.ImageView01);
Bitmap newImage = BitmapFactory.decodeByteArray(_data,0, _data.length);
image.setImageBitmap(newImage);

May have to change a little based on your program, but that's the basic idea
 
Back
Top Bottom