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

原文: 【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);
    }
}

猜你喜欢

转载自www.cnblogs.com/lonelyxmas/p/9473466.html