Android Camera use application
I wanted to write an application that makes use of the camera taking extremely slow frame-rate video and uploading it. Right now I am reading over this: http://itp.nyu.edu/~sve204/mobilemedia_spring10/androidCamera101.pdf
My question was in regards to the camera's use. The above article makes use of a canvas to preview the image, if one didn't want to preview the image before taking it could that be done? Is it necessary to use a preview of the camera image or can I just call takepicture to take the picture and catch the resulting callback to s开发者_C百科ave it to a file? If so how would that be done?
(It's been a long time since I've done any programming in Java)
Q:If one didn't want to preview the image before taking it could that be done?
A:No. Check out point 6 @ http://developer.android.com/reference/android/hardware/Camera.html
Important: Call startPreview() to start updating the preview surface. Preview must be started before you can take a picture.
Q:Is it necessary to use a preview of the camera image.
A:By "using" a preview of the image, do you mean setting the camera.setPreviewCallback(...)
? If so, no, it is not. But you still need the preview to draw to a canvas before you can take a picture, or else how is the user supposed to know how the picture will look like?
Q:Can I just call takepicture to take the picture and catch the resulting callback to save it to a file?
A:Yes you may by using camera.takePicture(...)
You can copy the data from the preview frame, to a byte array, then from another thread you can convert the byte array (NV21 Format), to whatever encoding you like (If you need to need to.. Android 2.2 has a very fast function in YuvImage Class which can convert to JPEG) and send it to a server.
Right now I'm running into an issue whereby if I try to call to take a picture inside the on-create using code similar to this: itp.nyu.edu/~sve204/mobilemedia_spring10/androidCamera101.pdf
it just crashes... I assume what's happening is it is trying to call to take the picture before the actual preview is setup.
精彩评论