Android的Camera.takePicture()不返回一些时间? [英] Android Camera.takePicture() does not return some times?

查看:229
本文介绍了Android的Camera.takePicture()不返回一些时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写为Android拍照的应用程序。在code上previewFrame(字节[]数据,相机摄像头)正从preVIEW一帧后进行一些处理。
问题是与android.hardware.Camera功能takePicture(),有时做的正是我想要的,有时不返回,没有回调将被调用。当我运行的应用程序有时拍摄第一张照片没有返回,有的时候,我可以把四张图片和第五会导致应用程序挂起。有一个呈三角主题:<一href=\"http://stackoverflow.com/questions/7258473/problem-with-taking-pictures-using-the-android-camera\">problem使用Android相机拍照。建议的解决方案是使用从去年preVIEW框架,但肯定它不是一个很好的解决方案!这个问题可能提价,是因为takePicture是Asancronous(<一个href=\"http://developer.android.com/reference/android/hardware/Camera.html#takePicture%28android.hardware.Camera.ShutterCallback,%20android.hardware.Camera.PictureCallback,%20android.hardware.Camera.PictureCallback,%20android.hardware.Camera.PictureCallback%29\"相对=nofollow> Android的文件)。

I am writing an application for android to take pictures. The code does some processing after getting a frame from preview in onPreviewFrame(byte[] data, Camera camera). The problem is with function takePicture() of android.hardware.Camera that sometimes do exactly what I want and sometimes does not return and no callbacks will be called. When I run the app some times taking the first picture does not return and some times I can take four pictures and the fifth will cause app to hang. There is a simillar thread: problem with taking pictures using the android camera. The suggested solution is to use the frame from last preview but surely it is not a good solution! This problem may raise because takePicture is Asancronous (Android Doc).

我简单地调用像这样takePicture()函数:

I simply call the takePicture() function like this:

public static void takePicture() {
   mCamera.takePicture(null, null, jpegCallback);
}

这里是logcat的输出的链接。您可以在输出与搜索短语takePicture,你会看到,这个函数返回有时,有时不返回。

Here is the link to Logcat output. You can search in the output with phrase "takePicture" and you will see that this function sometimes return and sometimes does not return.

这是输出时takePicture返回:

This is the output for when takePicture return:

10-02 19:24:36.570: INFO/ShotSingle(3198): ShotSingle::takePicture start
10-02 19:24:36.570: DEBUG/CameraHal(3198): 2489: takePicture() ENTER
10-02 19:24:36.570: DEBUG/MessageQueue(3198): MQ.put(5,0xb6590,0x0,0x8,0x80b0af55)
10-02 19:24:36.570: DEBUG/MessageQueue(3198): MessageQueue::put EXIT
10-02 19:24:36.578: DEBUG/MessageQueue(3198): MQ.get(5,0xb6590,0x0,0x8,0x80b0af55)
10-02 19:24:36.578: DEBUG/CameraHal(3198): 1458: CameraStop() ENTER
10-02 19:24:36.617: DEBUG/CameraHal(3198): 1543: CameraStop() EXIT
10-02 19:24:36.617: DEBUG/MessageQueue(3198): MQ.put(14,0xb6590,0x0,0x8,0x80b0af55)
10-02 19:24:36.617: DEBUG/MessageQueue(3198): MQ.get(14,0xb6590,0x0,0x8,0x80b0af55)
10-02 19:24:36.617: DEBUG/CameraHal(3198): 2497: takePicture() EXIT
10-02 19:24:36.617: INFO/ShotSingle(3198): ShotSingle::takePicture end

这是因为当takePicture不返回的输出:

and this is the output for when takePicture does not return:

10-02 19:25:20.671: INFO/ShotSingle(3198): ShotSingle::takePicture start
10-02 19:25:20.671: DEBUG/CameraHal(3198): 2489: takePicture() ENTER
10-02 19:25:20.671: DEBUG/MessageQueue(3198): MQ.put(5,0xb8cb8,0x0,0x8,0x80b0af55)
10-02 19:25:20.671: DEBUG/MessageQueue(3198): MessageQueue::put EXIT
10-02 19:25:21.343: INFO/StatusBarPolicy(3393): onSignalStrengthsChanged
10-02 19:25:22.609: WARN/PowerManagerService(3330): Timer 0x7->0x3|0x7
10-02 19:25:23.062: INFO/AudioStreamOutALSA(3198): (virtual android::status_t android::AudioStreamOutALSA::standby())  enter
10-02 19:25:23.125: ERROR/AudioStreamOutALSA(3198): Output standby called!!. Turn off PCM device.
10-02 19:25:23.125: INFO/ALSAStreamOps(3198): [ALSAStreamOps]codecOff mode = 0
10-02 19:25:23.234: INFO/AudioStreamOutALSA(3198): [AudioOutLock]Relase_wake_Lock 

有没有人有这个问题的任何解释或解决方案?

Does anyone have any explanation or solution for this problem?

推荐答案

看来这个问题是由于内存不足。我只是想问takePicture()之前解决它通过添加System.gc()的。

It seems that the problem is due to insufficient memory. I solved it by adding System.gc() just before calling takePicture().

System.gc();
CameraParameters.mCamera.takePicture(null, null, jpegCallback);

这篇关于Android的Camera.takePicture()不返回一些时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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