Usage of ShareMediaTask along with Isolated storage image

落爺英雄遲暮 提交于 2019-12-01 01:49:12

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.


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();
            }

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