将图像保存在 MediaLibrary 中

发布于 2024-12-18 21:30:19 字数 201 浏览 1 评论 0原文

我正在使用列表框,用具有绝对 uri 的图像填充列表框。现在我需要将图像保存到手机内的媒体库中。但是当我尝试时:

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

它会引发异常。有什么办法可以解决这个问题吗?

提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

余生一个溪 2024-12-25 21:30:19

这是我找到的解决方案并且有效:

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

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));
暖树树初阳… 2024-12-25 21:30:19

如果您使用绝对 Uri 引用图像,那么它们将不会成为应用程序的一部分,因此无法作为资源流进行访问。

您需要下载图像以直接获取流,然后将其写入媒体库。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文