【问题标题】:Saving PNG image to Isolated Storage for WP7将 PNG 图像保存到 WP7 的独立存储
【发布时间】:2012-04-28 21:08:38
【问题描述】:

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

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

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

【问题讨论】:

    标签: c# windows-phone-7 stream bitmapimage isolatedstorage


    【解决方案1】:

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

    假设您已安装来自 codeplex 的 image tools(通过 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

    【讨论】:

    • 不幸的是,这在 WP7 上不起作用 - 因为 WriteableBitmap-class 不包括 ToImage()- 方法。一个解决方案将不胜感激。
    • @Kris - ToImage 是图像工具包提供的扩展方法。 FWIW,我在提交之前在我的 Titan 上运行了它。
    • @Kris - 这对我来说也是一个有趣的问题,我没有意识到 WP7 的 png 支持有多差。如果您有任何其他问题,请告诉我,我很想调查一下。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多