1

我正在尝试从应用程序中拍摄照片和视频,并尝试通过分享魅力分享它,但我在这样做时遇到了问题。我拍完照片后,分享魅力说它无法分享图像。这是我的代码。任何人都可以让我知道我做错了什么。

namespace Temp
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class Page1 : Page
    {

        private StorageFile _photo; // Photo file to share
        private StorageFile _video; // Video file to share





        private async void OnCapturePhoto(object sender, TappedRoutedEventArgs e)
        {
            var camera = new CameraCaptureUI();
            var file = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (file != null)
            {
                _photo = file;
                DataTransferManager.ShowShareUI();
            }
        }



        private async void OnCaptureVideo(object sender, TappedRoutedEventArgs e)
        {
            var camera = new CameraCaptureUI();
            camera.VideoSettings.Format = CameraCaptureUIVideoFormat.Wmv;
            var file = await camera.CaptureFileAsync(CameraCaptureUIMode.Video);

            if (file != null)
            {
                _video = file;
                DataTransferManager.ShowShareUI();
            }
        }

        void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs args)
        {
            var request = args.Request;


            if (_photo != null)
            {
                request.Data.Properties.Description = "Component photo";
                var reference = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(_photo);
                request.Data.Properties.Thumbnail = reference;
                request.Data.SetBitmap(reference);
                _photo = null;

            }
            else if (_video != null)
            {
                request.Data.Properties.Description = "Component video";
                List<StorageFile> items = new List<StorageFile>();
                items.Add(_video);
                request.Data.SetStorageItems(items);
                _video = null;
            }

        }

      }


        protected override void OnNavigatedTo(NavigationEventArgs e)
        {

            DataTransferManager.GetForCurrentView().DataRequested += OnDataRequested;

        }







}
4

1 回答 1

1

为了让您的应用程序共享,您必须设置标题DataPackagePropertySet和至少一个“SetXXX”方法。如果不这样做,您将在尝试共享“来自 的数据有问题”时看到以下消息。

所以添加request.Data.Properties.Title = "Title_of_photo_or_video";事件OnDataRequested

于 2013-05-20T03:50:12.140 回答