从相机预览中捕获图像
我想知道是否可以保存相机预览中的图像,也许每 2-3 秒保存一张图像。你能给我一些例子吗?
我发现这是一个可能的解决方案,并且我知道如何从字节数组保存图像,但是如何继续保存每 N 帧?我正在考虑存储系统正常运行时间并在每一帧中检查它,但这似乎有点蹩脚。有更好的办法吗?有没有办法获取预览帧速率等信息?
tnx。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经能够使用 此处。在我的应用程序中,我还每 2-3 秒执行一次此操作以分析颜色。
您可以编写适当的
Runnable
并使用Handler.postDelayed()
(请参阅 docs) 以适当的时间间隔进行链式调用。您还可以将Message
和Handler.sendMessageDelayed()
与重写Handler.handleMessage()
结合使用以获得相同的效果。关键思想是在处理该消息的代码中包含发送(延迟)另一个相同消息的代码。这使得连续捕获成为可能。当您最终决定停止应用程序时,请小心清除消息管道!
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 useHandler.postDelayed()
(see docs) to chain call for the appropriate interval. You could also useMessage
andHandler.sendMessageDelayed()
in conjunction with overridingHandler.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!
您可以使用
CountDownTimer
。您必须重写onPreviewFrame
。在那里你调用YUV420
。在您的 CountDownTimer 中,您可以每 5 秒调用一次您自己的屏幕截图方法。或者您使用ArrayList
并从onPreviewFrame
添加位图。捕获屏幕截图后,您可以保存所有位图......You can use a
CountDownTimer
. You have to override theonPreviewFrame
. In there you call theYUV420
. In yourCountDownTimer
, you can call your own screenshot method every 5 seconds. or you use aArrayList<Bitmap>
and add your Bitmaps from theonPreviewFrame
. And after capture the screenshots, you can save all the Bitmaps....