adobe Air 网络摄像头问题
我一直在开发一个简单的桌面应用程序,使用adobe air、html和javascript将数据保存到sqlite(不是as,没有flash builder,没有flex)。有没有一种方法可以从我的网络摄像头捕获图像并使用这些技术保存它?如果不能,还可以做什么来达到这个结果?提前致谢。
I have been developing a simple desktop app using adobe air, html and javascript to save data to sqlite (not as, no flash builder, no flex). Is there a way that i can capture an image from my webcam and save it using these technologies ? If not what else can be done to achieve the result? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是可以做到的,但它绝对不利于性能:)你将得到巨大的字符串对象(更大的图像=更大的字符串)。但我会告诉你我是如何做到的。
首先,您必须从网络摄像头获取 BitmapData。这可以通过创建 BitmapData 对象并使用其 draw() 函数来完成,如下所示:
使用此 BitmapData,您可以调用 getPixels(),它将返回 ByteArray。
该 ByteArray 现在已准备好进行序列化。既然要存储,最好将其存储为字符串。这通常由 Base64 完成。您可以使用此类来实现base64编码,如下所示:
上面的字符串可以存储在您的sqlite中,并且是您图像的字符串表示形式。图像越大,转换所需的时间就越长。
要从 sqlite 中取回图像,您可以使用我提供给您的 Base64 类的decodeByteArray() 方法,并结合加载器对象。示例如下所示。
这就是您如何从数据库中存储和检索图像。
This can be done, but it is absolutely not performance-friendly :) You will get enormous string-objects (bigger images = bigger strings). But I will tell you how I did it once.
First, you have to get the BitmapData from your webcam. This can be done by creating a BitmapData-object and using its draw()-function, as shown below:
With this BitmapData, you can then call for getPixels(), which will return a ByteArray.
This ByteArray is now ready for serialization. Since you are storing, it is best you store it as a string. This is most commonly done by Base64. You can use this class to implement the base64-encoding, as shown below:
The above string can be stored in your sqlite and is a string-representation of your image. The bigger the image, the longer the conversion will take.
To get the image back from your sqlite, you can use the decodeByteArray()-method of the Base64-class I gave you, in combination with a loader-object. Example is shown below.
And this is how you can store and retrieve images from your database.