Click here to Skip to main content
15,868,164 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Problem

How put image logo inside of generated bar code ?

Details

I make windows application to generate c# qr code

I success to do that

I work in visual studio 2015 windows form applications

i using messagetoolkitqrcode

My code generated qr code by c# as following :

C#
private void button1_Click(object sender, EventArgs e)
        {
            using (SaveFileDialog sv = new SaveFileDialog() { Filter = "JPEG|*.jpg", ValidateNames = true })
            {
                if (sv.ShowDialog()==DialogResult.OK)
                {
                    MessagingToolkit.QRCode.Codec.QRCodeEncoder encoder = new MessagingToolkit.QRCode.Codec.QRCodeEncoder();
                    encoder.QRCodeScale = 8;
                    Bitmap bmp = encoder.Encode(textBox1.Text);
                    pictureBox1.Image = bmp;
                    bmp.Save(sv.FileName, ImageFormat.Jpeg);
                }

            }


        }


How to put logo inside my generated bare code as following image ?

my logo i need to put inside qr barcode is NASA logo when i generate it as following :

AND logo found in path

c/nasa.jpg

Simple File Sharing and Storage.[^]

What I have tried:

C#
How to put image logo within generated qr code
Posted
Updated 26-Jul-22 6:14am

1 solution

Creating a class:
public class QRCodeEncoderDemo
{
public static System.Drawing.Bitmap CombinImage(System.Drawing.Bitmap bit,string destImg)
{
System.Drawing.Image img = System.Drawing.Image.FromFile(destImg);

if (img.Height != 45 || img.Width != 45)

{

img = KiResizeImage(img, 45, 45, 0);

}

Graphics g = Graphics.FromImage(bit);
g.DrawImage(bit, 0, 0, bit.Width, bit.Height);
g.DrawImage(img, bit.Width / 2 - img.Width / 2, bit.Width / 2 - img.Width / 2, img.Width, img.Height);

GC.Collect();

return bit;
}

public static System.Drawing.Image KiResizeImage(System.Drawing.Image bmp, int newW, int newH, int Mode)
{
try
{
System.Drawing.Image b = new Bitmap(newW, newH);
Graphics g = Graphics.FromImage(b);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(bmp, new System.Drawing.Rectangle(0, 0, newW, newH), new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
g.Dispose();
return b;

}
catch
{
return null;
}

}

internal System.Drawing.Image GCode(object p)
{
throw new NotImplementedException();
}
}

Using the class:
bitmap = encoder.Encode(textQr.Text);
bitmap = QRCodeEncoderDemo.CombinImage(bitmap, fileName);
 
Share this answer
 
Comments
Richard Deeming 27-Jul-22 4:44am    
An unformatted, unexplained code-dump is not a good solution to any question - especially not when the question was asked 5½ years ago!

Edit your solution. Format the code. Add an explanation of what you are doing, and how it solves the question.

Without that, your solution is likely to be removed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900