Xamarin Camera2Basic示例在UnlockFocus调用后引发异常 [英] Xamarin Camera2Basic sample throws exception after UnlockFocus call

查看:184
本文介绍了Xamarin Camera2Basic示例在UnlockFocus调用后引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下载了Xamarin Camera2Basic项目

Downloaded Xamarin Camera2Basic project

最初,所有内容在Visual Studio 2017模拟器中开始测试时都可以正常工作.

Initially all works correctly as it's begin tested in Visual Studio 2017 emulator.

注释了"CameraCaptureStillPictureSessionCallback.cs"中的代码,如下所示,以允许单击拍摄照片"按钮后在模拟器屏幕上显示捕获的静止图像:

Commented out code inside "CameraCaptureStillPictureSessionCallback.cs" as shown below to allow the still image captured to be displayed on the emulator screen after clicking the "Take Picture" button:

public override void OnCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result)
{
    //Owner.ShowToast("Saved: " + Owner.mFile);
    //Log.Debug(TAG, Owner.mFile.ToString());
    //Owner.UnlockFocus();
}

单击拍摄照片"按钮将自身隐藏起来,并在屏幕上显示另一个标记为拍摄照片"的按钮(我在事后添加,并且代码位于Camera2BasicFragment.cs文件中,但该代码与问题).

Clicking the "Take Picture" button hides itself, and shows another button labeled "Retake Picture" on the screen (which I added after the fact and the code is located in the Camera2BasicFragment.cs file, but the code is inconsequential to the issue).

单击现在可见的拍摄照片"按钮,将执行以下操作:

Clicking the now visible "Retake Picture" button does the following:

  1. 隐藏自己
  2. 显示拍照"按钮
  3. 调用UnlockFocus()

UnlockFocus()允许摄像机的流连续显示在屏幕上,而不是先前捕获的静止图像.

UnlockFocus() allows the camera's stream to display continuously on the screen instead of the still image captured previously.

现在,当我再次单击拍摄照片"按钮(以尝试捕获新的静止图像)时,应用程序崩溃.

Now, when I click the "Take Picture" button again (to attempt to capture a new still image), the app crashes.

Visual Studio不提供任何有意义的错误消息.最有用的信息是在设备日志中显示的错误消息:

Visual studio does not provide any meaningful error messages. The closest useful bit of information are the error messages displayed int the Device Log:

07-26 23:29:03.201   10.1" Marshmallow (6.0.0) XHDPI Tablet Error   6987    BufferQueueProducer [ImageReader-640x480f100m2-6987-0] dequeueBuffer: can't dequeue multiple buffers without setting the buffer count  
07-26 23:29:07.174   10.1" Marshmallow (6.0.0) XHDPI Tablet Error   6987    RequestThread-0 Hit timeout for jpeg callback!  
07-26 23:29:03.201   10.1" Marshmallow (6.0.0) XHDPI Tablet Error   6987    Legacy-CameraDevice-JNI LegacyCameraDevice_nativeProduceFrame: Error while producing frame Function not implemented (-38).

我不确定这些错误的起因是什么,或者不确定要更改哪些设置/代码以使重拍"功能正常工作而不会导致应用程序崩溃.

I'm not sure what to make of these errors, or which settings/code to change to allow the "Retake Picture" functionality to work without crashing the app.

有什么建议吗?

根据请求,在哪里有我当前拥有的项目链接.

EDIT 1: Per request, where is a link to the project as I currently have it.

https://drive.google.com/file/d/0B7OSuA_ybXcFb081T210UlQzZkE/view?usp = sharing

以下是一些看似相关的信息:

Here is some other seemingly pertinent information:

  1. 此代码使用以下代码运行:

  1. This code was run using:

a. Windows 10专业版,Visual Studio 2017社区,Android模拟器 对于Visual Studio,Hyper-v虚拟管理器,Android 6.0 (Marshamallow SDK 23),平板电脑大小的模板

a. Windows 10 Pro, Visual Studio 2017 Community, Android Emulator For Visual Studio, Hyper-v Virtual Manager, Android 6.0 (Marshamallow SDK 23), Tablet sized template

b. 2013 Macbook Pro,适用于Mac的Visual Studio(最新版本),默认 emaulator,Android 6.0(Marshmallow SDK 23),平板电脑大小的模板.

b. 2013 Macbook Pro, Visual Studio For Mac (latest version), default emaulator, Android 6.0 (Marshmallow SDK 23), Tablet sized template.

在两个环境中都观察到第二次"LockFocus"调用后无法拍摄快照.

The failure to take snapshot after second "LockFocus" call is observed in both environments.

Mac使查找一些更有意义的错误变得更加容易:

The Mac made it easier to find some more meaninful errors:

a.我看到的错误发生在内部的方法"produceFrame"上 LegacyCameraDevice.java

a. The error I saw happened on method "produceFrame" inside LegacyCameraDevice.java

推荐答案

我也有这个演示的问题,其背后的真正问题是有关IOnImageAvailableListener的,它不会触发OnImageAvailable方法来保存图片.

I've the problem with this demo also, The real problem behind this is about the IOnImageAvailableListener, it will not trigger the OnImageAvailable method to save the picture...

阅读代码后,我发现该演示程序已损坏,缺少了一部分. 在Camera2BasicFragment.cs的OnCreateMethod中,您需要添加此行

After read the code, i found out that the demo is broken, it missing some piece. In the Camera2BasicFragment.cs, in the OnCreateMethod, you will need to add this line

mCaptureCallback = new CameraCaptureListener() { Owner = this};

整个方法应如下所示:

public override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        mStateCallback = new CameraStateListener() { owner = this };
        mSurfaceTextureListener = new Camera2BasicSurfaceTextureListener(this);

        // fill ORIENTATIONS list
        ORIENTATIONS.Append((int)SurfaceOrientation.Rotation0, 90);
        ORIENTATIONS.Append((int)SurfaceOrientation.Rotation90, 0);
        ORIENTATIONS.Append((int)SurfaceOrientation.Rotation180, 270);
        ORIENTATIONS.Append((int)SurfaceOrientation.Rotation270, 180);
    }

有趣的是,如果您在模拟器上运行此命令,则不会发生任何事情,因为在CameraCaptureListener.cs文件中,它将始终返回0,而不是ControlAFState.FocusedLocked或ControlAFState.InActivate

The interesting thing is, if you run this on emulator, nothing will happened, because in the CameraCaptureListener.cs file, this will always return 0, not ControlAFState.FocusedLocked or ControlAFState.InActivate

Integer afState = (Integer)result.Get(CaptureResult.ControlAfState);

如果我破解了If方法以便能够运行跳入下一个步骤,则ImageAvailableListener.cs的OnImageAvaiable方法将永远不会被模拟器触发.但是,如果我在真实设备上运行,它可以正常运行吗?!

Event if i hack the If method to be able to run jump into next step, the method OnImageAvaiable of ImageAvailableListener.cs will never be triggered by emulator. But if i run on the real device, it ran fine ?!

因此解决方法是: 1.添加上面的代码,就像我在onCreate函数上说明的那样. 2.不要使用模拟器来运行Camera2,这是有问题的.

So the fix is: 1. Add the code above like i explained on the onCreate function. 2. Don't use emulator to run Camera2, it's buggy.

希望对您有所帮助:)

这篇关于Xamarin Camera2Basic示例在UnlockFocus调用后引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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