gpt4 book ai didi

c# - 将 PNG 图像保存到 WP7 的隔离存储

转载 作者:太空宇宙 更新时间:2023-11-03 14:02:27 25 4
gpt4 key购买 nike

这里有很多图像到隔离存储的问题,但我找不到适合我的情况的好答案 - 所以我们开始吧。

我正在从网络上获取 .png 图像,并将其保存为 BitmapImage 对象。完成加载后(在 BitmapImage.ImageOpened 事件上),我想将它保存到独立存储。

那么,我如何从这个 BitmapImage(或直接从网络 - 无关紧要)获取字节或文件流,以便将其写入我的 IsolatedStorageFileStream?我无法在 Internet 上找到关于它的单个帖子,该帖子适用于 WP7(因此 BitmapImage.StreamSource 不可用)和 .png 图像。任何帮助将不胜感激。

最佳答案

我不认为你可以开箱即用,但有一个 codeplex/nuget 项目可以让你以 png 格式保存。

假设您有 image tools来自已安装的 codeplex(通过 nuget!)。

_bi = new BitmapImage(new Uri("http://blog.webnames.ca/images/Godzilla.png", UriKind.Absolute));
_bi.ImageOpened += ImageOpened;
...

private void ImageOpened(object sender, RoutedEventArgs e)
{
var isf = IsolatedStorageFile.GetUserStoreForApplication();

using (var writer = new StreamWriter(new IsolatedStorageFileStream("godzilla.png", FileMode.Create, FileAccess.Write, isf)))
{
var encoder = new PngEncoder();
var wb = new WriteableBitmap(_bi);
encoder.Encode(wb.ToImage(), writer.BaseStream);
}
}

John Pappa 有一篇关于这项技术的优秀博客文章。 Saving snapshots to PNG

关于c# - 将 PNG 图像保存到 WP7 的隔离存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10359448/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com