Saving Image in MediaLibrary

夙愿已清 提交于 2020-01-02 07:47:27

问题


I am using listbox where I am populating the listbox with the images with the absolute uri. Now i need to save the images to my media library within my phone. But when I try:

Application.GetResourceStream(new Uri(imageurl, UriKind.absolute))

it fires an exception. Is there any way to solve this problem.

Thanks in advance.


回答1:


Here's what I found as solution and it worked:

        WebClient client = new WebClient();
        client.OpenReadCompleted += (s, e) =>
            {
                if (e.Error == null)
                {
                    MediaLibrary library = new MediaLibrary();
                    library.SavePicture(imageName, e.Result);
                }
            };
        client.OpenReadAsync(new Uri(imageAbsoluteUrl, UriKind.Absolute));



回答2:


If you're referencing imageswith an absolute Uri then they won't be part of the application and so therefore not accessible as a resource stream.

You'll need to download the image to get the stream directly and then write it to the media library.



来源:https://stackoverflow.com/questions/8307382/saving-image-in-medialibrary

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