QRCoder icon indicating copy to clipboard operation
QRCoder copied to clipboard

QRCode' does not contain a definition for 'GetGraphic' and no accessible extension method 'GetGraphic' accepting a first argument of type 'QRCode' could be found

Open ANKUSH-032 opened this issue 2 years ago • 1 comments

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-032 avatar Jan 10 '23 06:01 ANKUSH-032

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

Benjlet avatar Apr 01 '23 02:04 Benjlet