1
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 3 years have passed since last update.

コンソールアプリ.NET 5.0でZXing.NETを使ったQRコード読み取り

1
Posted at

目的

現在最新環境でZXing.NETを使ったWindowsのコンソールアプリでQRコードを読み取る。
QRコードが含まれた画像ファイルをコマンドライン引数で指定するようにする。

前提条件

  • Visual Studio 2019でC# / .NET 5.0 / コンソールアプリ で新規プロジェクト作成済状態

ライブラリ追加

NuGetで以下の2つのライブラリをインストール。
ZXing.NET ver.0.16.6(2020/10/9版)
System.Drawing.Common (最新の安定板)

ソースコード作成

Hello Worldアプリをベースに例えば こんな感じに。

Program.cs
using System;
using System.Drawing;
using ZXing;

namespace namespaceHogeHoge
{
    class Program
    {
        static void Main(string[] args)
        {
            // load a bitmap
            Image bmpImg = Bitmap.FromFile(args[0]);
            try
            {
                Bitmap bitmap = new Bitmap(bmpImg);
                BarcodeReader reader = new BarcodeReader();
                Result result = reader.Decode(bitmap);
                Console.WriteLine("'" + result.ToString().Trim() + "'" + "was found.");
            }
            catch (Exception)
            {
                Console.WriteLine("Image not found");
            }
        }
    }
}

ビルドして実行してみる

おわり

1
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
1
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?