我有一个问题。在初始化相机进行预览并将另一个应用程序置于焦点后,再回到我的应用程序时:预览会显示黑色。如果我继续拍照,它会拍摄我通常指向相机的位置。
我在OnResume()覆盖方法上做错了什么吗?相关代码如下:
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();
}
感谢您的帮助. :)