Reinit Rear View Camera

I have a problem. After initializing the camera to preview and focusing another application, return to my application: the preview is displayed in black. If I continue to take a picture, it takes a picture where I usually point the camera.

Am I doing something wrong in overriding OnResume ()? Relative code 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(); } 

Thank you for your help. :)

+6
source share
1 answer

onResume() is called too early. At this point you do not have a surface holder. You can try to present the onPostResume() handler in your activity and / or handle the SurfaceHolder.Callback.surfaceChanged() event.

+6
source

Source: https://habr.com/ru/post/922334/


All Articles