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

2024-01-23

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

我正在取一个.png来自网络的图像,并将其另存为BitmapImage-目的。当它完成加载时(在BitmapImage.ImageOpened事件),我想将其保存到隔离存储中。

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


我不认为你可以开箱即用地做到这一点,但有一个 codeplex/nuget 项目允许你以 png 格式保存。

假设你有图像工具 http://imagetools.codeplex.com从安装的 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 有一篇关于这项技术的优秀博客文章。将快照保存为 PNG http://johnpapa.net/saving-snapshots-to-png-in-silverlight-4-and-the-webcam

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将 PNG 图像保存到 WP7 的隔离存储 的相关文章

随机推荐