简体   繁体   English

从相机预览中捕获图像

[英]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. 我想知道是否可以从相机预览中保存图像,也许每2-3秒保存1张图像。 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? 我已经发现这是一种可能的解决方案,并且我知道如何从字节数组保存图像,但是如何继续保存每N帧? i was thinking of storing the system uptime and checking it in every frame but it seems kinda lame. 我当时想存储系统的正常运行时间并在每帧中进行检查,但这似乎有些la脚。 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? Android:如何将预览框架另存为JPEG图像?

tnx. tnx。

I have been able to convert images from the preview stream to a usable format using the YUV420-to-RGB algorithm presented here . 我已经能够使用此处介绍的YUV420-to-RGB算法将预览流中的图像转换为可用格式。 In my application, I also do this every 2-3 seconds for the purposes of analysing the colour. 在我的应用程序中,我还每2-3秒执行一次此操作,以分析颜色。

You can write an appropriate Runnable and use Handler.postDelayed() (see docs ) to chain call for the appropriate interval. 您可以编写适当的Runnable并使用Handler.postDelayed() (请参阅docs )在适当的时间间隔内链式调用。 You could also use Message and Handler.sendMessageDelayed() in conjunction with overriding Handler.handleMessage() for the same effect. 您也可以将MessageHandler.sendMessageDelayed()与重写Handler.handleMessage()结合使用,以达到相同的效果。

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 . 您可以使用CountDownTimer You have to override the onPreviewFrame . 您必须重写onPreviewFrame In there you call the YUV420 . 在那儿您叫YUV420 In your CountDownTimer , you can call your own screenshot method every 5 seconds. CountDownTimer ,您可以每5秒调用一次自己的屏幕截图方法。 or you use a ArrayList<Bitmap> and add your Bitmaps from the onPreviewFrame . 或者您使用ArrayList<Bitmap>并从onPreviewFrame添加您的位图。 And after capture the screenshots, you can save all the Bitmaps.... 在捕获了屏幕截图之后,您可以保存所有位图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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