【问题标题】:How to using memory stream to save image without using save file dialog如何在不使用保存文件对话框的情况下使用内存流保存图像
【发布时间】:2017-01-30 00:05:47
【问题描述】:

如何使用内存流替换保存文件对话框?

我为姓名、国家和会员生成二维码

生成的二维码没有任何问题

但我需要使用内存流来保存 qr 的图像,而不是使用保存文件对话框

我的代码如下

 using (SaveFileDialog sv = new SaveFileDialog() { Filter = "JPEG|.jpg", ValidateNames = true })
                    {
                        if (sv.ShowDialog() == DialogResult.OK)
                        {
                            MessagingToolkit.QRCode.Codec.QRCodeEncoder encoder = new MessagingToolkit.QRCode.Codec.QRCodeEncoder();
                            encoder.QRCodeScale = 8;


                            string encoding = "UserName : " + textBox4.Text + "\r\n" + "Country : " + comboBox3.Text + "\r\n" + "Membership :" + comboBox5.Text;


                            Bitmap bmp = encoder.Encode(encoding);
                            pictureBox1.Image = bmp;
                            path = sv.FileName;
                            bmp.Save(path, ImageFormat.Jpeg);
                        }

                    }

如何使用内存流替换保存文件对话框?

【问题讨论】:

  • 您的问题在所示代码的上下文中几乎没有意义。您认为将位图保存到 MemoryStream 会实现什么效果。

标签: .net winforms c#-4.0


【解决方案1】:

您可以直接将位图保存到内存流中:

MemoryStream memoryStream = new MemoryStream();
bmp.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);

【讨论】:

    猜你喜欢
    • 2011-12-22
    • 1970-01-01
    • 1970-01-01
    • 2022-12-12
    • 2013-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多