c# - 如何在 WPF 中将图像保存到文件

标签 c# wpf image

我是 wpf 控件和框架的新手。我似乎无法保存我的图像,你能帮我吗 下面是我的代码

            SaveFileDialog sfd = new SaveFileDialog();
            sfd.FileName = System.IO.Path.GetFileNameWithoutExtension(newlist[currentPicture]);                              
            Nullable<bool> result = sfd.ShowDialog();
            if (result == true)
            {

                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(newlist[currentPicture]);
                bmp.Save(newlist[currentPicture]);
            }

最佳答案

对于 System.Drawing.Bitmap,您需要将对话框的 FileName 属性传递给 Save 方法。

编辑:在 WPF 中:

var encoder = new PngBitmapEncoder()
encoder.Frames.Add(BitmapFrame.Create(image));
using (var stream = dialog.OpenFile())
    encoder.Save(stream);

关于c# - 如何在 WPF 中将图像保存到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4383294/

相关文章:

css - 覆盖 div 在 Chrome 和 FF 中有效,但在 IE 中无效?

c# - 从网站 asp.net 转移到 android 以及从 android 转移到网站 aps.net?

asp.net - 无法摆脱 "Login failed for user IIS APPPOOL\NETWORKSERVICE"

C# 为字节数组或图像创建哈希

C#/WPF 应用程序抛出 ObjectDisposedException;为什么我无法捕获或获取堆栈跟踪?

.net - 阻止 WPF ComboBox 中的文本自动完成?

html - 仅在 HTML/CSS 中以最小宽度/高度缩放 ​​HTML 中的图像

c# - 使用 LINQ 过滤掉空集合属性

C# 407 需要代理身份验证

c# - 优先自动复位事件