2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

C#でQRコードを生成してみる

Posted at

1. はじめに

  • C#でQRコードを作成して画像を表示したい
  • ZXing.Netを使用してQRコードを作成したい

2. 開発環境

  • C#
  • .NET 8
  • Visual Studio 2022
  • Windows 10

3. 事前準備

  • ZXing.Net ,ZXing.Net.Bindings.Windows.Compatibility をNuGetからインストールする
    image.png

4. サンプルコード

using ZXing;
using ZXing.Common;
using ZXing.Windows.Compatibility;

namespace ZXingSample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            string URL = "https://qiita.com";
            var bitmap = GenerateQRcode(URL);

            pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
            pictureBox1.Image = bitmap;
        }

        /// <summary>
        /// QRコード生成
        /// </summary>
        /// <param name="URL"></param>
        /// <returns></returns>
        private Bitmap GenerateQRcode(string URL)
        {
            var qrWriter = new BarcodeWriter()
            {
                Format = BarcodeFormat.QR_CODE,
                Options = new EncodingOptions { Height = 100, Width = 100, Margin = 0 },
            };

            return qrWriter.Write(URL);
        }
    }
}

5. 実行結果

image.png

6. 参考文献

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?