Hello,
Welcome to our Microsoft Q&A platform!
Based on your error, The reason for this error is that we are capturing a capture (that is, when taking a picture), cameraCaptureSession.capture(createCaptureImageRequest(), cameraCaptureSessionCaptureCallback, null);
the captureRequest
parameter requires addTarget
a surface, and the surface must be cameraDevice.createCaptureSession(previewSurfaceList , CameraCaptureSessionStateCallback, null);
a subset of this previewSurfaceList
, otherwise an exception will be reported
I find a similar thread based on your error when using Camera2.
https://stackoverflow.com/questions/55206571/how-do-i-get-the-camera2-api-to-work-a-second-time
After change the front camera, I use following code in CameraViewServiceRenderer.cs
,
public void TakePicture()
{
if (_camera._cameraId == "0")
{
_camera.LockFocus();
}
else
{
_camera.CaptureStillPicture();
}
}
Then open the CameraDroid.cs
, I achieve this function.
public void CaptureStillPicture()
{
try
{
if ( null == CameraDevice)
{
return;
}
// THIS WAS NOT RELEASING THE RESOURCES AND SHOULD BE REMOVED FROM THE SAMPLE!
//// This is the CaptureRequest.Builder that we use to take a picture.
////if (stillCaptureBuilder == null)
//// stillCaptureBuilder = mCameraDevice.CreateCaptureRequest(CameraTemplate.StillCapture);
// This is the proper code
var stillCaptureBuilder = CameraDevice.CreateCaptureRequest(CameraTemplate.StillCapture);
stillCaptureBuilder.AddTarget(_imageReader.Surface);
// Use the same AE and AF modes as the preview.
stillCaptureBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.ContinuousPicture);
SetAutoFlash(stillCaptureBuilder);
// Orientation
IWindowManager windowManager = Context.GetSystemService(Context.WindowService).JavaCast<IWindowManager>();
var rotation = windowManager.DefaultDisplay.Rotation;
// int rotation = (int)_context.WindowManager.DefaultDisplay.Rotation;
stillCaptureBuilder.Set(CaptureRequest.JpegOrientation, (int)rotation);
_previewSession.StopRepeating();
_previewSession.AbortCaptures();
try
{
_previewSession.Capture(stillCaptureBuilder.Build(), new CameraCaptureStillPictureSessionCallback(), null);
}
catch (System.Exception e)
{
throw;
}
}
catch (CameraAccessException e)
{
e.PrintStackTrace();
}
}
Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.