画面表示(スクリーンショット)から、QRコードを読み込んで、デコードする
C#の単体アプリです
※同様の機能のフォームアプリはこちら
https://qiita.com/santarou6/items/d1090338def65f3af5bc
screen_qr_decode.cs
//c:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /reference:QRCodeEncoderDecoderLibrary.dll /target:winexe screen_qr_decode.cs
using System;
using System.Windows.Forms;
using System.Drawing;
using QRCodeEncoderDecoderLibrary;
public class screen_qr_decode
{
public static void Main(string[] args)
{
try{
QRDecoder QRCodeDecoder;
Bitmap QRCodeInputImage;
QRCodeDecoder = new QRDecoder();
QRCodeInputImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height);
Graphics g = Graphics.FromImage(QRCodeInputImage);
g.CopyFromScreen(new Point(0, 0), new Point(0, 0), QRCodeInputImage.Size);
g.Dispose();
QRCodeInputImage.Save("temporary.png", System.Drawing.Imaging.ImageFormat.Png);
byte[][] DataByteArray = QRCodeDecoder.ImageDecoder(QRCodeInputImage);
//string Result = System.Text.Encoding.GetEncoding(932).GetString(DataByteArray[0]);
string Result = System.Text.Encoding.UTF8.GetString(DataByteArray[0]);
//string Result = System.Text.Encoding.GetEncoding(51932).GetString(DataByteArray[0]);
MessageBox.Show(Result);
}
catch(Exception ex){
MessageBox.Show("読み取りエラー\n\n"+ex);
}
}
}
※ライブラリは以下参照
QR Code Encoder and Decoder .NET Class Library
https://www.codeproject.com/Articles/1250071/QR-Code-Encoder-and-Decoder-NET-Class-Library-Writ
QRCodeEncoderDecoderLibrary.dll