Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

C# ZXing.Net でサクッと QR コードを生成してみる

0
Posted at

はじめに

ZXing.Net でサクッと QR コードを生成してみる備忘録です。

改訂履歴

  • 2026/09/07 : 初版公開。

本文

1. 環境

  • .NET 8.0
  • Visual Studio Community 2022
  • ZXing.Net 0.16.11
  • ZXing.Net.Bindings.Windows.Compatibility 0.16.16

2. 実装例

ZXing.Net は Java 用に開発されたライブラリ ZXing を .NET に移植したものだそうです。ライセンスは Apache 2.0 です。なお ASP.NET で使うなら Bitmap でなく PNG 等の画像データを byte[] で返すようにした方が良いですね。

QrCodeHelper.cs
using ZXing;
using ZXing.QrCode;
using ZXing.Windows.Compatibility;

namespace ZXingNetExample;

/// <summary>
/// QR コード関連の処理を提供します。
/// </summary>
public static class QrCodeHelper
{
    /// <summary>
    /// QR コードを生成します。
    /// </summary>
    /// <param name="url">QR コードに埋め込む URL。</param>
    /// <returns>生成された QR コードのビットマップ。</returns>
    public static Bitmap Create(string url)
    {
        var writer = new BarcodeWriter<Bitmap>
        {
            Format = BarcodeFormat.QR_CODE,
            Options = new QrCodeEncodingOptions
            {
                Height = 200,
                Width = 200,
                Margin = 1
            },
            Renderer = new BitmapRenderer()
        };

        return writer.Write(url);
    }
}

3. 動作確認

テストアプリを作って https://qiita.com/ で QR コードを作ってみました。

おわりに

ZXing は Zebra Crossing(ゼブラ・クロッシング)に由来する名前だそうです。めちゃめちゃ格好良いですね。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?