LoginSignup
0
2

More than 3 years have passed since last update.

画面表示(スクリーンショット)から、QRコードを読み込んで、デコードするC#の単体アプリです

Last updated at Posted at 2019-07-27

画面表示(スクリーンショット)から、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);
    }

 }

}

実行例
キャプチャ.PNG

※ライブラリは以下参照
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

0
2
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
0
2