【发布时间】:2016-11-30 06:44:33
【问题描述】:
我正在关注这个项目 https://github.com/ThatCSharpGuy/Forms-FullCameraPage 以实现 xamarin 形式的相机。它可以正常工作,但我想创建自己的空白来拍照。我在该项目中对当前项目的唯一更改是我将 CameraPage 设置为 Contentpage XAML 而不是类。
我们的想法是创建一个函数,以便在 10 秒内拍摄照片,如果可能的话,我想在我的共享代码中控制它。
如果我们查看我添加的代码,这就是我目前得到的。
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; }
}
}
}
这段代码的问题是我的函数的结果似乎为空。好像我没有得到图像。所以我的问题是:我需要调用SetPhotoResult 函数才能拍照吗?如果是这样,我做错了什么?
【问题讨论】:
标签: c# xamarin xamarin.forms