question

hosseintavakoli-7723 avatar image
0 Votes"
hosseintavakoli-7723 asked RobCaplan edited

capture image by front camera in Camera2Basic xamarin

I useing Camera2basic.

when I use rear camera it capture a picture correctly, but when I switch on front camera capture picture not working.


button switch camera code :
this code working correctly show front camera view.

 public void OnClick(View v)
         {
             if (v.Id == Resource.Id.picture)
             {
                 string CAMERA_FRONT = "1";
                 string CAMERA_BACK = "0";
                 if (WhatCameraIsOn.Equals(CAMERA_FRONT))
                 {
                     WhatCameraIsOn = CAMERA_BACK;
                     CloseCamera();
                     OpenCamera(mTextureView.Width, mTextureView.Height);
                 }
                 else if (WhatCameraIsOn.Equals(CAMERA_BACK))
                 {
                     WhatCameraIsOn = CAMERA_FRONT;
                     CloseCamera();
                     OpenCameraFront(mTextureView.Width, mTextureView.Height);
                 }
              }
          }

Button Picture Click code:
this code take picture only by rear camera.

         public void OnClick(View v)
         {
             if (v.Id == Resource.Id.picture)
             {
                     TakePicture();
              }
          }

How can I take picture by front camera
here is my app picture


dotnet-xamarin
capture.png (340.3 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JarvanZhang-MSFT avatar image
0 Votes"
JarvanZhang-MSFT answered JarvanZhang-MSFT edited

Hello,​

Welcome to our Microsoft Q&A platform!

Hi, hosseintavakoli. To take picture with front camera, try to replace the mCaptureSession.Capture(..) command with CaptureStillPicture() method.

private void LockFocus()
{
    try
    {
        // This is how to tell the camera to lock focus.
        mPreviewRequestBuilder.Set(CaptureRequest.ControlAfTrigger, (int)ControlAFTrigger.Start);
        // Tell #mCaptureCallback to wait for the lock.
        mState = STATE_WAITING_LOCK;
        //mCaptureSession.Capture(mPreviewRequestBuilder.Build(), mCaptureCallback,mBackgroundHandler);
        CaptureStillPicture();
    }
    catch (CameraAccessException e)
    {
        e.PrintStackTrace();
    }
}


Best Regards,

Jarvan Zhang



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.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.