我需要使用 Xamarin Forms PCL 访问相机。我找不到任何有效的样本。
我尝试安装XLab并使用它的示例代码,但它有例外。例如,对于 XLabs 示例,我使用以下内容:
/// <summary>
/// Takes the picture.
/// </summary>
/// <returns>Take Picture Task.</returns>
internal async Task<MediaFile> TakePicture()
{
Setup();
ImageSource = null;
return await _mediaPicker.TakePhotoAsync(new CameraMediaStorageOptions { DefaultCamera = CameraDevice.Front, MaxPixelDimension = 400 }).ContinueWith(t =>
{
if (t.IsFaulted)
{
Status = t.Exception.InnerException.ToString();
}
else if (t.IsCanceled)
{
Status = "Canceled";
}
else
{
var mediaFile = t.Result;
ImageSource = ImageSource.FromStream(() => mediaFile.Source);
return mediaFile;
}
return null;
}, _scheduler);
}
/// <summary>
/// Setups this instance.
/// </summary>
private void Setup()
{
if (_mediaPicker != null)
{
return;
}
var device = Resolver.Resolve<IDevice>();
////RM: hack for working on windows phone?
_mediaPicker = DependencyService.Get<IMediaPicker>() ?? device.MediaPicker;
}
我得到以下异常Resolver.Resolve<IDevice>():
IResolver has not been set. Please set it by calling Resolver.SetResolver(resolver)
如何使用此或其他替代方法使用 Xamarin.Forms 拍照?提前感谢您的任何提示!