OnResume相机REINIT黑屏 [英] OnResume Camera Reinit Black Screen
问题描述
我有一个问题。初始化相机为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();
}
感谢您的帮助。 :)
推荐答案
<一个href=\"http://developer.android.com/reference/android/app/Activity.html#onResume%28%29\"><$c$c>onResume()$c$c>所谓得太早。您没有表面持有者准备在这个阶段。你可以尝试引入<一个href=\"http://developer.android.com/reference/android/app/Activity.html#onPostResume%28%29\"><$c$c>onPostResume()$c$c>处理您的活动,和/或处理<一个href=\"http://developer.android.com/reference/android/view/SurfaceHolder.Callback.html#surfaceChanged%28android.view.SurfaceHolder,%20int,%20int,%20int%29\"><$c$c>SurfaceHolder.Callback.surfaceChanged()$c$c>事件。
这篇关于OnResume相机REINIT黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!