PictureCallback.onPictureTaken从来不叫 [英] PictureCallback.onPictureTaken never called

查看:726
本文介绍了PictureCallback.onPictureTaken从来不叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写,需要用相机拍摄的照片的应用程序。当我尝试采取实际的图片会出现问题。这里的code是困扰我:

I am writing an application that needs pictures taken with the camera. The problem occurs when I try to take an actual picture. Here's the code that is troubling me:

    final ShutterCallback shutterCallback = new ShutterCallback() {
        @Override
        public void onShutter() {
            Log.d(TAG, "onShutter");
        }
    };

    final PictureCallback callback = new PictureCallback() {

        @Override
        public void onPictureTaken(byte[] data, Camera camera) {
            Log.d(TAG, "onPictureTaken - jpeg");
            try {
                //async task for storing the photo
                new SavePhotoTask(CameraView.this.ctx, data).execute();
            } catch (final SavePhotoException e) {
                //some exceptionhandling
            }
        }
    };
    this.camera = Camera.open();
    this.camera.setPreviewDisplay(surfaceHolder);
    final Camera.Parameters parameters = findBestParameters(w, h);
    this.camera.setParameters(parameters);
    this.camera.startPreview();
    Log.d(TAG, "takePicture now!");
    this.camera.takePicture(shutterCallback, null, callback);

在它似乎摸出仿真器,但在我的手机(摩托罗拉Defy - 的Andr​​oid 2.1)。

On the emulator it seems to work out but on my phone (Motorola Defy - android 2.1).

实际问题:在手机上的picturecallback永远不会发生onPictureTaken被永远不会被调用。该Shuttercallback仍将执行,但对方是不是(我试着用原料代替JPEG,同样的事情)。

The actual problem: on the phone the picturecallback is never happening "onPictureTaken" gets never called. The Shuttercallback is executed but the other is not (and I tried with raw instead of jpeg, same thing).

有谁知道这个问题?我只是不明白的地方的不同之处在于,以模拟器现在。我AP preciate你的帮助。

Does anyone know this problem? I just don't see where the difference lies to the emulator right now. I appreciate your help.

推荐答案

我终于和调试问题。突然它的工作,因为调试慢得多:这是一个时间问题。回调需要一些时间被调用。在调试手机有足够的时间来完成拍摄照片...

I finally went and debugged the problem. All of a sudden it worked, because debugging is much slower: It's a timing problem. The callback takes some time to be called. While debugging the phone had enough time to finish taking the picture ...

另外不要去调用Camera.stop preVIEW()和Camera.release()太早了。

Also don't go calling Camera.stopPreview() and Camera.release() too early.

这篇关于PictureCallback.onPictureTaken从来不叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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