A QR code is a computer-readable identification that contains data about the item to which it is attached. The article demonstrates how to return the QR Code image as a response from .Net Core API. QR-Code Live Demo Prerequisites Visual Studio or Visual Studio Code already installed Install the below package, i.e., “QRCoder” via NuGet package manager. Let’s Start The “QRCoder” DLL helps generate QR codes with just four lines of code in C#. 4 Lines of Code Snippet = new QRCodeGenerator(); = qrGenerator.CreateQrCode(qrText, QRCodeGenerator.ECCLevel.Q); = new QRCode(qrCodeData); = qrCode.GetGraphic(20); QRCodeGenerator qrGenerator QRCodeData qrCodeData QRCode qrCode Bitmap qrCodeImage Description of each line of code Create an instance of the QRCodeGenerator class. Initialize the QR code generator class: = new QRCodeGenerator(); QRCodeGenerator qrGenerator The next step is to initialize QR code data using the CreateQrCode method, which takes two arguments, i.e., string text for encoding inside the QR code, and another case defines the error correction level, i.e., ECCLevel. Create QR code data: Here, four different levels L (7%), M (15%), Q (25%), and H (30%) are available, whereby the percentage represents the hidden portion of the QR-code until the error correction algorithm can’t recreate the original message encoded in the QR code. = qrGenerator.CreateQrCode(qrText, QRCodeGenerator.ECCLevel.Q); QRCodeData qrCodeData The next step is to create the QR-code using the data initialized above. Generate QR code: QRCode qrCode = ; new QRCode( ) qrCodeData Finally, represent the QR code into a graphical image, as shown below. The method takes one argument, which defines the size of the QR-code. The method return image in the form of Bitmap by default. Create a graphical image: GetGraphic GetGraphic = qrCode.GetGraphic(20); Bitmap qrCodeImage How to return QR-code Image from .Net Core API response? Controller GET route snippet uses the QR-code library and returns the QR code image as a response. public IActionResult { QRCodeGenerator qrGenerator = ; QRCodeData qrCodeData = qrGenerator. ; QRCode qrCode = ; Bitmap qrCodeImage = qrCode. ; return , ); } [H ] ttpGet [R (" { }")] oute qenerate / qrText GetQrCode( ) string qrText new QRCodeGenerator() CreateQrCode( , QRCodeGenerator.ECCLevel.Q) qrText new QRCode( ) qrCodeData GetGraphic(20) File(BitmapToBytes( ) qrCodeImage "image/jpeg" QR-code, by default, generates a Bitmap, below function used to convert Bitmap to bytes. Bitmap to bytes function code snippet: static Byte { using (MemoryStream stream = ) { img. ; return stream. ; } } private [] BitmapToBytes(Bitmap ) img new MemoryStream() Save( , System.Drawing.Imaging.ImageFormat.Png) stream ToArray() Example of QR-code with my publication “ ” logo Optional parameters & overloads: The Tech Masters Bitmap qrCodeImage = qrCode.GetGraphic( , Color.DarkRed, Color.PaleGreen, ); Bitmap qrCodeImage = qrCode.GetGraphic( , , ); Bitmap qrCodeImage = qrCode.GetGraphic( , Color.Black, Color.White, (Bitmap)Bitmap.FromFile( )); //Set color by using Color-class types 20 true //Set color by using HTML hex color notation 20 "#000ff0" "#0ff000" //Set logo in center of QR-code 20 "C:\\myimage.png" consist of QR-code generation implemented in ASP.Net Core API. Github Repo: default & custom colored ssukhpinder/QRCodeExample Thank you for reading. Keep visiting and share this in your network. Disclaimer: The author provides this code and software “AS IS”, without warranty of any kind, express or implied, including but not limited to fitness for a particular purpose and non-infringement. In no event shall the author be liable for any claim, damages or other liability in connection with the software or code provided here