开发者

Single Frame image from Camera Preview Android

开发者 https://www.devze.com 2023-02-12 18:20 出处:网络
I want to be able to take a snapshot of a preview camera screen being displayed on a SurfaceView. I know it has something to do with the onPreviewFrame() method and this returns a byte array in YUV fo

I want to be able to take a snapshot of a preview camera screen being displayed on a SurfaceView. I know it has something to do with the onPreviewFrame() method and this returns a byte array in YUV format but I have no idea how to call the onPreviewFrame() method on it's own.

I have used it in conjunction with Camera.setPreviewCallback() but this is a continuous thing that keeps generating the开发者_开发百科 image, I need it to do it once on an onClick(), to pretty much take a photo without making the preview window stop. Any ideas?


For anybody else with a similar problem to this I solved it by using the setOneShotPreviewCallback() method on the camera object to give me a byte[] with the information for the image. with that its can be used to create a YUV and then compressed to bitmap or whatever you need.


Capture the preview image into a canvas and hold a lock to it. You can then easily save to a BitMap Refer this post for complete explanation with sample code http://www.anddev.org/using_camerapreview_to_save_a_picture_on_disk-t226.html

0

精彩评论

暂无评论...
验证码 换一张
取 消