Spire.Barcode is a professional barcode library specially designed for .NET developers (C#, VB.NET, ASP.NET, .NET Core) and Java developers (J2SE and J2EE) to generate, read and scan 1D & 2D barcodes.

Fri Aug 04, 2023 11:31 am

Im using Spire.Office 8.7.0.

I want to generate a qr code with a logo inside.
The logo is appearing fine, but I can't change the size of the logo.
I tried playing around with ImageWidth and ImageHeight but it doesn't seem to have any effect.

Code: Select all
           
BarcodeSettings settings = new BarcodeSettings
            {
                Type = BarCodeType.QRCode,
                QRCodeECL = QRCodeECL.M,
                ShowText = false,
                X = 5f,
                Data = vCardContent.ToString(),
                ForeColor = Color.Gray,
                Unit = (int)GraphicsUnit.Pixel,
                ImageWidth = Convert.ToInt64(250),
                ImageHeight = Convert.ToInt64(250),
                Data2D = vCardContent.ToString(),
                QRCodeLogoImage = Image.FromFile(_environment.ContentRootPath + $"/assets/images/logo.jpg")
            };

            BarCodeGenerator generator = new BarCodeGenerator(settings);
            Image image = generator.GenerateImage();

            MemoryStream ms = new MemoryStream();
            image.Save(ms, ImageFormat.Png);
            ms.Position = 0;
            return new FileStreamResult(ms, "image/png");

twindberg
 
Posts: 4
Joined: Fri May 25, 2018 1:24 pm

Mon Aug 07, 2023 3:04 am

Hi,

Thanks for your inquriy.
Kindly note that BarcodeSettings.ImageHeight and BarcodeSettings.ImageHeight are settings for the QR-code image size. Please use the following code to modify the added image size .
Code: Select all
Image image = Image.FromFile(@"test.png ");
Size size = new Size(8, 8);
Bitmap newImage = new Bitmap(image, size);
newImage.Save("result.png", ImageFormat.Png);
...
QRCodeLogoImage = Image.FromFile("result.png");

If there are any further questions or concerns, just feel free to contact us.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Mon Aug 07, 2023 9:00 am

Hi Triste,

working fine. Thank you very much

twindberg
 
Posts: 4
Joined: Fri May 25, 2018 1:24 pm

Mon Aug 07, 2023 9:59 am

Hi,

Thanks for your feedback.
I am delighted to hear that the code works for your issue. If you have any other questions, just feel free to contact us. We are here to assist you.

Have a nice day! :D

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.Barcode