如何捕获不保存文件到手机/ SD卡的Andr​​oid相机图像? [英] How to capture an Android Camera image without saving a file to the phone/sdcard?

查看:157
本文介绍了如何捕获不保存文件到手机/ SD卡的Andr​​oid相机图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想捕捉的图像与Android相机,但因为图像可以包含敏感数据我不想保存到手机或SD卡中的图像。相反,我想一个base64字符串(COM pressed),这将被立即发送到服务器

I would like to capture an image with the Android Camera but because the image may contain sensitive data I dont want the image saved to the phone or sd card. Instead I would like a base64 string (compressed) which would be sent to the server immediately

在PhoneGap的似乎文件会自动保存到不同的地方。
本身我从来没有能够得到的图像流 - 在onJpegPictureTaken()字节[]参数总是空

In PhoneGap it seems files are saved to various places automatically. Natively I was never able to get the image stream - in onJpegPictureTaken() the byte[] parameter was always null.

任何人都可以提出一个方法?

can anyone suggest a way?

推荐答案

请参阅Camera.on previewFrame()和YuvImage.com presstoJpeg()能够得到一个字节数组可以转化成位图。

See Camera.onPreviewFrame() and the YuvImage.compresstoJpeg() to be able to get a byte array you can convert into a bitmap.

注意YuvImage.com pressToJpeg()仅在SDK提供8或更高版本,我想。对于早期版本,你需要实现自己的YUV德$ C $铬。周围有几个例子,或者,我可以为你提供一个例子。

Note that YuvImage.compressToJpeg() is only available in SDK 8 or later, I think. For earlier versions you'll need to implement your own YUV decoder. There are several examples around or, I could provide you an example.

这两种方法都会让你得到内存中的摄像机图像,却一直没有坚持到SD。要注意的是大多数相机preVIEW大小的位图将迅速咀嚼内存pretty,你就需要非常小心地回收位图,可能也有规模下来了一点做很多与他们仍适合于大多数设备的机堆限制内。

Those two methods will allow you to get a camera picture in memory and never persist it to SD. Beware that bitmaps of most camera preview sizes will chew up memory pretty quickly and you'll need to be very careful to recycle the bitmaps and probably also have to scale them down a bit to do much with them and still fit inside the native heap restrictions on most devices.

祝你好运!

这篇关于如何捕获不保存文件到手机/ SD卡的Andr​​oid相机图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆