I'm currently making a custom view to preview camera of the device, and trying to trigger a "take picture" event.
Right now, i can trigger the event, but i don't find a solution to return the picture to Xamarin Forms Shared Code.
Here's what i'm doing from the Xamarin Forms custom control :
public class CameraPreview : View
{
public event EventHandler TakePictureRequested;
public void TakePicture()
{
TakePictureRequested?.Invoke(this, EventArgs.Empty);
}
}
And here from Native code for Android for example :
protected override void OnElementChanged(ElementChangedEventArgs<CameraPreview> e)
{
base.OnElementChanged(e);
if (e.OldElement != null)
{
e.OldElement.TakePictureRequested += OnTakePictureRequested;
}
if (e.NewElement != null)
{
if (Control == null)
{
cameraPreview = new CameraPreviewView(Context);
SetNativeControl(cameraPreview);
}
Control.Preview = Camera.Open(getBackCameraId());
e.NewElement.TakePictureRequested += OnTakePictureRequested;
}
}
void OnTakePictureRequested(object sender, EventArgs e)
{
cameraPreview.TakePicture();
}
The idea is that "OnTakePictureRequested" from Native Code can return the value to the Xamarin Forms.
Anyone has an idea ? Thanks
TaskCompletionSource- shanranm