本文介绍了OnResume相机REINIT黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题。初始化相机为preVIEW并把另一个应用程序成为关注的焦点,然后回到我的应用程序之后:preVIEW显示了黑色。如果我继续拍照,它需要的,我通常将相机指向的图片。

I have a problem. After initializing the camera for a preview and bringing another app into focus, then back to my app: the preview shows up black. If I continue to take a picture, it takes a picture of where I point the camera normally.

我做得不对的OnResume()重写?相对code是如下:

Am I doing something wrong on the OnResume() override? Relative code is below:

public void ReleaseCamera()
    {
        if (myCamera != null)
        {
            myCamera.Release();
            myCamera = null;
        }
    }

protected override void OnPause()
    {
        base.OnPause();

        if (myButtonState == ButtonState.CameraActive)
            ReleaseCamera();
    }

protected override void OnResume()
    {
        base.OnResume();

        if (myButtonState == ButtonState.CameraActive)
            InitializeCamera();
    }

private void InitializeCamera()
    {
        SurfaceView mySurfaceView = FindViewById<SurfaceView>(Resource.Id.surfaceView1);

        myCamera = Android.Hardware.Camera.Open(cameraNumber);
        Android.Hardware.Camera.Parameters p = myCamera.GetParameters();

        myCamera.SetDisplayOrientation(90); // Portrait
        myCamera.SetPreviewDisplay(mySurfaceView.Holder);
        myCamera.StartPreview();
    }

感谢您的帮助。 :)

推荐答案

<$c$c>onResume()所谓得太早。您没有表面持有者准备在这个阶段。你可以尝试引入<$c$c>onPostResume()处理您的活动,和/或处理<$c$c>SurfaceHolder.Callback.surfaceChanged()事件。

这篇关于OnResume相机REINIT黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 22:52