Csharp/C#教程:将PNG图像保存到WP7的隔离存储分享


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

这里有相当多的图像到隔离存储问题,但我找不到适合我情况的好答案 – 所以我们走了。

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

那么,我怎样才能从这个BitmapImage(或直接来自网络)获取字节或文件流 – 这无关紧要,以便我可以将它写入我的IsolatedStorageFileStream ? 我无法在互联网上找到一篇关于它的文章, BitmapImage.StreamSource适用于WP7(因此BitmapImage.StreamSource不可用).png图像。 任何帮助将不胜感激。

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

假设你安装了codeplex的图像工具 (通过nuget!)。

 _bi = new BitmapImage(new Uri("https://sofzh.miximages.com/c%23/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

上述就是C#学习教程:将PNG图像保存到WP7的隔离存储分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/942353.html

(0)
上一篇 2021年11月13日
下一篇 2021年11月13日

精彩推荐