Usage of ShareMediaTask along with Isolated storage image

▼魔方 西西 提交于 2019-11-30 21:04:11

问题


Is it possible to use ShareMediaTask along with the image save on the isolated storage. I tried to implement the same by applying the below given code. But when i run the code the current page flashes and comes back to the same page.

  var shareMediaTask = new ShareMediaTask { FilePath = "isostore:" + LocalImagePath };
  shareMediaTask.Show();

回答1:


Sorry, currently ShareMediaTask only supports items in the Media Library either in the Camera Roll folder of the Saved Pictures folder. That's done due to security reasons. If for example you use ShareMediaTask and share with another app, that app should never have access to your app's IsoStore. For that reason, ShareMediaTask doesn't currently support IsoStore file paths.

Here's an end-to-end code sample of how to save an image into the MediaLibrary Saved Pictures and use the ShareMediaTask @ http://www.reflectionit.nl/Blog/PermaLink620a4c87-a4af-4007-b4bc-81d851b11658.aspx

private void ButtonShare_Click(object sender, RoutedEventArgs e) {
    var bmp = new WriteableBitmap(this.ContentPanel, null);
    var width = (int)bmp.PixelWidth;
    var height = (int)bmp.PixelHeight;
    using (var ms = new MemoryStream(width * height * 4)) {
        bmp.SaveJpeg(ms, width, height, 0, 100);
        ms.Seek(0, SeekOrigin.Begin);
        var lib = new MediaLibrary();
        var picture = lib.SavePicture(string.Format("test.jpg"), ms);

        var task = new ShareMediaTask();

        task.FilePath = picture.GetPath();

        task.Show();
    }
}

You can also save pictures into the Camera Roll folder and use the ShareMediaTask using the MediaLibrary.SavePictureToCameraRoll() extension method.




回答2:



I have done with the following code :

 BitmapImage bi = new BitmapImage(new Uri(string.Format("Data/{0}/{1}", Category, img), UriKind.Relative)));
        bi.CreateOptions = BitmapCreateOptions.BackgroundCreation;
        bi.ImageOpened += (s1, e1) =>
        {
            var bmp = new WriteableBitmap(bi);

            var width = (int)bmp.PixelWidth;
            var height = (int)bmp.PixelHeight;

            using (var ms = new MemoryStream(width * height * 4))
            {
                bmp.SaveJpeg(ms, width, height, 0, 100);
                ms.Seek(0, SeekOrigin.Begin);
                var lib = new MediaLibrary();
                Picture picture = null;
                try
                {
                    picture = lib.SavePicture(string.Format("test.jpg"), ms);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }

                var task = new ShareMediaTask();

                task.FilePath = picture.GetPath();

                task.Show();
            }

        };


来源:https://stackoverflow.com/questions/13855377/usage-of-sharemediatask-along-with-isolated-storage-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!