2

I am making QR code generator in windows forms and I want to draw a string under the generated QR code and save the picture in a folder.

This is my code for now

using (SaveFileDialog sfd = new SaveFileDialog() { Filter = "JPEG|*.jpg", ValidateNames = true })
{
    if (sfd.ShowDialog() == DialogResult.OK)
    {
        BarcodeWriter barcodeWriter = new BarcodeWriter();
        EncodingOptions encodingOptions = new EncodingOptions() { Width = 300, Height = 300, Margin = 0, PureBarcode = false };
        encodingOptions.Hints.Add(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
        barcodeWriter.Renderer = new BitmapRenderer();
        barcodeWriter.Options = encodingOptions;
        barcodeWriter.Format = BarcodeFormat.QR_CODE;
        Bitmap bitmap = barcodeWriter.Write((txt1.Text + "/" + txt2.Text + "/" + txt3.Text + "/" + txt4.Text + "/" + txt5.Text + "/" + txt6.Text + "/" + txt7.Text));
        Bitmap logo = new Bitmap($"{Application.StartupPath}/sabx.png");
        Graphics g = Graphics.FromImage(bitmap);
        g.DrawImage(logo, new Point((bitmap.Width - logo.Width) / 2, (bitmap.Height - logo.Height) / 2));
        pictureBox1.Image = bitmap;
    }
}
Palle Due
  • 5,929
  • 4
  • 17
  • 32

0 Answers0