i am following this project https://github.com/ThatCSharpGuy/Forms-FullCameraPage to implement a camera in xamarin forms. it works without any problem but i would like to create my own void to take the photo. The only thing i have changed in that project to my current one is that I have made the CameraPage to a Contentpage XAML instead of a class.
The idea is to make a function so the photo gets taken in 10 seconds and i want to control this in my shared code if it is possible.
if we look at the code that i have added this is what i got so far.
public CameraPage()
{
InitializeComponent();
loadCameraFunction (); //so this is the function that i created myself
}
//i added this and put the same value into them as the ones in `SetPhotoResult`
byte[] image;
int width = -1;
int height = -1;
//the void
async void loadCameraFunction()
{
await Task.Delay (10000); //wait 10 sec for the photo to be taken
SetPhotoResult(image, width, height); //i add the byte[] and two ints i created above that has the same value as the ones in SetPhotoResult
}
public delegate void PhotoResultEventHandler(PhotoResultEventArgs result);
public event PhotoResultEventHandler OnPhotoResult;
public void SetPhotoResult(byte[] image, int width = -1, int height = -1)
{
OnPhotoResult?.Invoke(new PhotoResultEventArgs(image, width, height));
}
public void Cancel()
{
OnPhotoResult?.Invoke(new PhotoResultEventArgs());
}
public class PhotoResultEventArgs : EventArgs
{
public PhotoResultEventArgs()
{
Success = false;
}
public PhotoResultEventArgs(byte[] image, int width, int height)
{
Success = true;
Image = image;
Width = width;
Height = height;
}
public byte[] Image { get; private set; }
public int Width { get; private set; }
public int Height { get; private set; }
public bool Success { get; private set; }
}
}
}
Problem i have with this code is that the result from my function seems to be null. It seems like i dont get the image. So my question is: Is the SetPhotoResult function what i need to call in order to take the photo? And if so, what am I doing wrong?