Xamarin所有操作系统:使用CrossMedia.Current.TakePhotoAsync拍照

时间:2016-08-26 15:08:13

标签: android ios xamarin.forms uwp

我正在创建一个项目,我必须拍摄很多照片。在我以前的iOS项目中,一切正常。我正在为所有平台(iOS,Android和UWP)的新项目使用相同的代码。

当我在Android上拍照时,流是空的。在UWP中,当我尝试打开可以拍照的页面时,应用程序被阻止:3-5分钟后它被解锁并且我可以拍照。

我正在使用James Montemagno MediaPlugIn最新版本。

代码非常简单

    /// <summary>
    /// Executes the camera command.
    /// </summary>
    /// <returns>The camera command.</returns>
    public async Task ExecuteCameraCommand() {
        var file = await CrossMedia.Current.TakePhotoAsync(
                                new Plugin.Media.Abstractions.StoreCameraMediaOptions());

        if (file == null)
            return;

        byte[] imageAsBytes = null;
        using (var memoryStream = new MemoryStream()) {
            file.GetStream().CopyTo(memoryStream);
            file.Dispose();
            imageAsBytes = memoryStream.ToArray();
        }

        if (imageAsBytes.Length > 0) {
            var resizer = DependencyService.Get<IImageResize>();
            imageAsBytes = resizer.ResizeImage(imageAsBytes, 1080, 1080);

            var imageSource = ImageSource.FromStream(()=>new MemoryStream(imageAsBytes));
            _images.Add(new GalleryImage {Source=imageSource,OrgImage=imageAsBytes});
        }
    }

任何帮助或想法? 提前谢谢!

0 个答案:

没有答案