Recently, I download Aspose.BarCode nuget package 18.10,and used it generate QR Code successfully,but I couldn’t find the way to generate a QR with logo.
Can you tell me what should I do to generate a QR with logo when I use class BarCodeGenerator?
Thanks!
For working with Aspose.BarCode for .NET, you may find the sample code at the link given below describing the way to use image in place of code text:
https://docs.aspose.com/display/barcodenet/Barcode+with+Image+In+Place+of+Codetext
For working with Aspose.BarCode for Java, please follow the link below:
https://docs.aspose.com/display/barcodejava/Creating+a+QR+Barcode#CreatingaQRBarcode-CreateQRBarcodewithLogo
Thanks fot your reply,I use the Aspose.BarCode for .NET, but I don’t see any code at the link you give me (Barcode with Logos|Documentation).
Is there any other way to generate QR with logo?
Please find the code sample given below:
using (BarCodeGenerator builder = new BarCodeGenerator(EncodeTypes.EAN13, "123456789012"))
{
// Generate Barcode image and store it in a Bitmap
using (System.Drawing.Bitmap barcode = builder.GenerateBarCodeImage())
{
// Load the logo/other image as Bitmap
using (System.Drawing.Bitmap picture = (System.Drawing.Bitmap)System.Drawing.Image.FromFile(@"D:\favicon.png"))
{
// Create a new empty image with new Calculated height & width
using (System.Drawing.Bitmap output = new System.Drawing.Bitmap(System.Math.Max(barcode.Width, picture.Width), barcode.Height + picture.Height))
{
// Get the Graphics object
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(output))
{
// Clear the canvas
g.Clear(System.Drawing.Color.White);
// Draw the primary image (barcode image) on the canvas
g.DrawImage(picture, new System.Drawing.PointF(0, 0));
// Draw the second image (logo image) on the canvas inside the barcode image
g.DrawImage(barcode, new System.Drawing.PointF(0, picture.Height));
}
output.Save(@"D:\output123.jpg");
}
}
}
}
There is a another question: builder.GenerateBarCodeImage() will return a value which type is Aspose.BarCode.Bitmap , why the barcode’s type is System.Drawing.Bitmap?
How to convert them?
The output of provided sample code is a JPG image containing generated barcode with provided logo image. It is requested to please elaborate your requirements so that we could look into it.
The problem is the code you give me can’t work.
when I compile it ,this line: using (System.Drawing.Bitmap barcode = builder.GenerateBarCodeImage())
because of type mismatch,throw an exception.so I want to know how to convert Aspose.BarCode.Bitmap to System.Drawing.Bitmap.
Thanks!
We have tested the sample code with latest version of Aspose.BarCode for .NET 18.11 and it is working fine. You may find the generated output JPG image here output123.png (3.5 KB).
Moreover, it is requested to please share your application with us and also mention which framework are you using so that we could investigate the issue.
OK,I just new a .Net Framework 4.6.2 console project and it can generate QR code with logo successfully when I use Aspose.BarCode for .NET 18.11 and System.Deawing.Common 4.5.1.
BUt when I use the same code and same nuget reference in a .Net standard 2.0 console project,it still can’t work,so when it can work in a .Net Standard project?
Thanks!
Thank you for writing back to us.
We have reproduced this issue and it has been logged with ID “BARCODENET-37031” for further investigation. You will automatically be informed here once we have more information to share.
Here is code example which helps to convert between Aspose Bitmap and MS Bitmap
public static System.Drawing.Bitmap ConvertBitmapAsposeToMS(Aspose.BarCode.Bitmap aOrigBitmap)
{
MemoryStream lMemStr = new MemoryStream();
aOrigBitmap.Save(lMemStr, Aspose.BarCode.ImageFormat.Bmp);
lMemStr.Position = 0;
System.Drawing.Bitmap lResBmp = new System.Drawing.Bitmap(lMemStr);
lResBmp.SetResolution(aOrigBitmap.HorizontalResolution, aOrigBitmap.VerticalResolution);
return lResBmp;
}
public static Aspose.BarCode.Bitmap ConvertBitmapMSToAspose(System.Drawing.Bitmap aOrigBitmap)
{
MemoryStream lMemStr = new MemoryStream();
aOrigBitmap.Save(lMemStr, System.Drawing.Imaging.ImageFormat.Bmp);
lMemStr.Position = 0;
Aspose.BarCode.Bitmap lResBmp = new Aspose.BarCode.Bitmap(lMemStr);
lResBmp.SetResolution(aOrigBitmap.HorizontalResolution, aOrigBitmap.VerticalResolution);
return lResBmp;
}
using (BarCodeGenerator builder = new BarCodeGenerator(EncodeTypes.EAN13, "123456789012"))
{
using (System.Drawing.Bitmap output = ConvertBitmapAsposeToMS(builder.GenerateBarCodeImage()))
{
output.Save(@"d:\save\rec\output123.jpg", System.Drawing.Imaging.ImageFormat.Png);
}
}
MSAsposeBitmap.zip contains two conversion functions Aspose->MS, MS->Aspose.
MSAsposeBitmap.zip (442 Bytes)