从相机拍照,无需预览 [英] Taking picture from camera without preview

查看:36
本文介绍了从相机拍照,无需预览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 Android 1.5 应用程序,该应用程序在启动后立即启动.这是一个Service,应该在没有预览的情况下拍照.该应用程序将记录某些区域的光密度.我可以拍照,但照片是黑色的.

I am writing an Android 1.5 application which starts just after boot-up. This is a Service and should take a picture without preview. This app will log the light density in some areas whatever. I was able to take a picture but the picture was black.

经过长时间的研究,我遇到了一个关于它的错误线程.如果您不生成预览,则图像将是黑色的,因为 Android 相机需要预览以设置曝光和对焦.我已经创建了一个 SurfaceView 和监听器,但是 onSurfaceCreated() 事件永远不会被触发.

After researching for a long time, I came across a bug thread about it. If you don't generate a preview, the image will be black since Android camera needs preview to setup exposure and focus. I've created a SurfaceView and the listener, but the onSurfaceCreated() event never gets fired.

我想原因是,表面不是在视觉上创建的.我还看到了一些使用 MediaStore.CAPTURE_OR_SOMETHING 静态调用相机的例子,它拍摄一张照片并用两行代码保存在所需的文件夹中,但它也没有拍摄照片.

I guess the reason is, the surface is not being created visually. I've also seen some examples of calling the camera statically with MediaStore.CAPTURE_OR_SOMETHING which takes a picture and saves in the desired folder with two lines of code, but it doesn't take a picture too.

我是否需要使用 IPC 和 bindService() 来调用这个函数?或者是否有其他方法可以实现这一目标?

Do I need to use IPC and bindService() to call this function? Or is there an alternative method to achieve this?

推荐答案

Android 平台上的相机在提供有效的预览表面之前无法流式传输视频真的很奇怪.该平台的架构师似乎根本没有考虑 3rd 方视频流应用程序.即使对于增强现实情况,图片也可以作为某种视觉替代呈现,而不是实时相机流.

it is really weird that camera on android platform can't stream video until it given valid preview surface. it seems that the architects of the platform was not thinking about 3rd party video streaming applications at all. even for augmented reality case the picture can be presented as some kind of visual substitution, not real time camera stream.

无论如何,您可以简单地将预览表面的大小调整为 1x1 像素并将其放在小部件(视觉元素)的某个角落.请注意 - 调整预览表面的大小,而不是相机框架大小.

anyway, you can simply resize preview surface to 1x1 pixels and put it somewhere in the corner of the widget (visual element). please pay attention - resize preview surface, not camera frame size.

当然,这种技巧并不能消除不需要的数据流(用于预览),这会消耗一些系统资源和电池.

of course such trick does not eliminate unwanted data streaming (for preview) which consumes some system resources and battery.

这篇关于从相机拍照,无需预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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