从相机预览中捕获图像

发布于 2024-10-11 05:13:04 字数 324 浏览 7 评论 0原文

我想知道是否可以保存相机预览中的图像,也许每 2-3 秒保存一张图像。你能给我一些例子吗?

我发现这是一个可能的解决方案,并且我知道如何从字节数组保存图像,但是如何继续保存每 N 帧?我正在考虑存储系统正常运行时间并在每一帧中检查它,但这似乎有点蹩脚。有更好的办法吗?有没有办法获取预览帧速率等信息?

Android:如何将预览帧保存为 jpeg 图像?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

·深蓝 2024-10-18 05:13:04

我已经能够使用 此处。在我的应用程序中,我还每 2-3 秒执行一次此操作以分析颜色。

您可以编写适当的 Runnable 并使用 Handler.postDelayed() (请参阅 docs) 以适当的时间间隔进行链式调用。您还可以将 MessageHandler.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 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!

笑着哭最痛 2024-10-18 05:13:04

您可以使用CountDownTimer。您必须重写onPreviewFrame。在那里你调用YUV420。在您的 CountDownTimer 中,您可以每 5 秒调用一次您自己的屏幕截图方法。或者您使用 ArrayList 并从 onPreviewFrame 添加位图。捕获屏幕截图后,您可以保存所有位图......

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....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文