【C#/WPF】保存BitmapImage数据到文件中

参考:

http://stackoverflow.com/questions/35804375/how-do-i-save-a-bitmapimage-from-memory-into-a-file-in-wpf-c

/// <summary>
/// 把内存里的BitmapImage数据保存到硬盘中
/// </summary>
/// <param name="bitmapImage">BitmapImage数据</param>
/// <param name="filePath">输出的文件路径</param>
public static void SaveBitmapImageIntoFile(BitmapImage bitmapImage, string filePath)
{
    BitmapEncoder encoder = new PngBitmapEncoder();
    encoder.Frames.Add(BitmapFrame.Create(bitmapImage));

    using (var fileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
    {
        encoder.Save(fileStream);
    }
}
posted @ 2017-03-29 16:33  霍莉雪特  阅读(3070)  评论(0编辑  收藏  举报