如何将 UltraQRCodeBarcode Infragistics WinForms 控件转换为图像?

How do I convert an UltraQRCodeBarcode Infragistics WinForms control into image?

我有一个 QR 控件,它可以完美地生成 QR 码,当我用我的 phone 扫描它时,它工作得很好。但我无法将其转换为图像,因此无法将其保存到数据库中。我查看了他们的网站,但找不到任何东西,他们只有 WPF 或 Web 在 WinForms 上什么都没有。 这是我生成二维码的方法

private void btnGenerate_Click(object sender, EventArgs e)
{
    string data = string.Empty;
    var fullName = txtFirstName + " " + txtMiddleName + " " + txtLastName;
    if (!string.IsNullOrEmpty(txtLicenceNumber.Text))
    {
        data = fullName;
        data += ", " + Environment.NewLine + txtDistrict.Text;
        data += ", " + Environment.NewLine + txtLicenceNumber.Text;
        data += ", " + Environment.NewLine + txtRegistrationCode;
    }
    ultraQRCodeBarcode1.Data = data;
}

这是我的保存方法,我试图将其转换为字节码并保存 但是我没有成功,因为在这个中没有 属性 作为图像。

user.QrCode = ImageToByteArray(ultraQRCodeBarcode1.);

图片转换器

private byte[] ImageToByteArray(string imagePath)
{
    byte[] data = null;
    var fileInfo = new FileInfo(imagePath);
    long numBytes = fileInfo.Length;
    var fileStream = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
    var binaryReader = new BinaryReader(fileStream);
    data = binaryReader.ReadBytes((int)numBytes);
    return data;
}

UltraQRCodeBarcode 有 SaveTo 方法。此方法有多个重载,允许您将 QR 码保存到图像或内存流中。在您的情况下,我会创建一个内存流,然后将此流转换为字节数组,如下所示:

byte[] data;
using(MemoryStream ms = new MemoryStream())
{
    this.ultraQRCodeBarcode1.SaveTo(ms, ImageFormat.Png);
    byte[] data = ms.ToArray();
}