I've got a QR control that is perfectly generating the QR Code and when I scan it with my phone, it works perfectly. But I'm not able to convert that to an Image so I can save that to the database. I've looked on their website and I can't find anything, all they have is with WPF or Web nothing on WinForms. Here is how I generate QR code
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;
}
and This is my save method Where I'm trying to convert that to the Byte code and save But I'm not successful there is no property as Image in this one.
user.QrCode = ImageToByteArray(ultraQRCodeBarcode1.);
Image converter
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 has SaveTo method. This method has several overloads allowing you to save your QR code to image or to memory stream. In your case I would create a memory stream and then convert this stream to byte array like this:
byte[] data;
using(MemoryStream ms = new MemoryStream())
{
this.ultraQRCodeBarcode1.SaveTo(ms, ImageFormat.Png);
byte[] data = ms.ToArray();
}