QRCode' does not contain a definition for 'GetGraphic' and no accessible extension method 'GetGraphic' accepting a first argument of type 'QRCode' could be found
I am trying to generate QRCode in .Net 6 but get a error Tell me where is my code wrong
QRCodeGenerator qrCodeGenerator = new(); string data = "Name : " + employeeSalaryGetDetails.Name + "\n DOB : " + employeeSalaryGetDetails.DayofBirth.ToString() + "\n Email Address : " + employeeSalaryGetDetails.EmailId.ToString(); QRCodeData qrCodeData = qrCodeGenerator.CreateQrCode(data, QRCodeGenerator.ECCLevel.Q); QRCode qrCoder = new(); qrCoder.Equals(qrCodeData); Image rqCodeImage = qrCoder.GetGraphic(20);
var bytes = ImageToByteArray(rqCodeImage);
return File(bytes, "image/tmp");
Ankush,
The syntax on the frontpage of this GitHub might be for an older version - the below code works fine for me in .NET 6, referencing QRCoder v1.4.3:
string data = "Your data here";
string path = @"image/example.png"
QRCodeData qrCodeData = QRCoder.QRCodeGenerator.GenerateQrCode(data, QRCoder.QRCodeGenerator.ECCLevel.Q);
BitmapByteQRCode qrCode = new QRCoder.BitmapByteQRCode(qrCodeData);
byte[] bytes = qrCode.GetGraphic(50);
File.WriteAllBytes(path, bytes);
There are of course much nicer ways of writing this but illustrates it is still working on the latest.
Cheers