简体   繁体   中英

Capture an image from the camera preview

i was wondering if it is possible to save images from the camera preview, maybe 1 image every 2-3 seconds. any examples you can give me?

i have found this as a possible solution, and i know how to save the image from byte array, but how do i proceed with saving every Nth frame? i was thinking of storing the system uptime and checking it in every frame but it seems kinda lame. Is there a better way? Is there a way i can get info such as preview frame rate?

Android: How to save a preview frame as jpeg image?

tnx.

I have been able to convert images from the preview stream to a usable format using the YUV420-to-RGB algorithm presented here . In my application, I also do this every 2-3 seconds for the purposes of analysing the colour.

You can write an appropriate Runnable and use Handler.postDelayed() (see docs ) to chain call for the appropriate interval. You could also use Message and Handler.sendMessageDelayed() in conjunction with overriding Handler.handleMessage() for the same effect.

The key idea is to include code to send (delayed) another identical message in the code to handle that message. This enables continuous capture. Be careful to clear the message pipeline when you eventually decide to stop your application!

You can use a CountDownTimer . You have to override the onPreviewFrame . In there you call the YUV420 . In your CountDownTimer , you can call your own screenshot method every 5 seconds. or you use a ArrayList<Bitmap> and add your Bitmaps from the onPreviewFrame . And after capture the screenshots, you can save all the Bitmaps....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM