コード例 #1
0
        Task IMessageSubscriber <ActivityResultMessage> .ReceiveMessageAsync(
            ActivityResultMessage message)
        {
            if (message.RequestCode == LauncherRequestIds.PhotoChooser)
            {
                var messenger = Dependency.Resolve <IMessenger>();
                messenger.Unsubscribe(this);

                PhotoResult photoResult;

                if (message.ResultCode == Result.Ok)
                {
                    var uri = message.Intent.Data;

                    var context = Dependency.Resolve <Context>();

                    string fileName = GetFileName(context, uri);

                    if (string.IsNullOrWhiteSpace(fileName))
                    {
                        string extension = GetExtension(context, uri);
                        fileName = "Unknown." + extension;
                    }

                    photoResult = new PhotoResult
                    {
                        Uri = uri,
                        OriginalFileName = fileName,
                        LauncherResult   = LauncherResult.OK
                    };
                }
                else
                {
                    photoResult = new PhotoResult
                    {
                        LauncherResult = LauncherResult.Cancel
                    };
                }

                OnCompleted(photoResult);
            }

            return(Task.CompletedTask);
        }
コード例 #2
0
ファイル: PhotoLauncher.Uwp.cs プロジェクト: leijiancd/Codon
        public async Task <PhotoResultBase> ShowAsync()
        {
            CameraCaptureUI dialog = new CameraCaptureUI();

            if (PixelHeight > 0 || PixelWidth > 0)
            {
                dialog.PhotoSettings.CroppedSizeInPixels = new Size(PixelWidth, PixelHeight);
            }
            StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (file != null)
            {
                var result = new PhotoResult()
                {
                    ChosenPhoto      = await file.OpenStreamForReadAsync(),
                    OriginalFileName = file.Name
                };

                return(result);
            }

            return(null);
        }