LoginSignup
0
0

More than 3 years have passed since last update.

tif画像を連続で読み込んで、テキストのQRコードの内容を書き出し

Last updated at Posted at 2019-11-20

QRコードシリーズ

exeをクリックすると同階層以下の、ファイルをなめて、tifファイルをすべて、QR読み込みし、テキストに書き出すツール。

↓これの続きです
ーーー
画面表示(スクリーンショット)から、QRコードを読み込んで、デコードするC#の単体アプリ⇒テキスト書き出し版
https://qiita.com/santarou6/items/9a26c28828c1dd1a6556
ーーー

tiff_qr_decode.cs

//c:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /reference:QRCodeEncoderDecoderLibrary.dll /target:winexe tiff_qr_decode.cs

using System;
using System.Windows.Forms;
using System.Drawing;
using QRCodeEncoderDecoderLibrary;

public class tiff_qr_decode
{
 public static void Main(string[] args)
 {
    QRDecoder   QRCodeDecoder;
    Bitmap      QRCodeInputImage;
    QRCodeDecoder = new QRDecoder();

    DateTime dt = DateTime.Now;
    string dt_s = dt.ToString("yyyyMMdd_HHmmss");
    System.IO.File.WriteAllText(@".\" + dt_s + ".txt", dt_s + Environment.NewLine);

    string appPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

    System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(appPath);
    System.IO.FileInfo[] files = di.GetFiles("*.tif", System.IO.SearchOption.AllDirectories);

    foreach (System.IO.FileInfo f in files)
    {
        System.IO.File.AppendAllText(@".\" + dt_s + ".txt", f.FullName);
        System.IO.File.AppendAllText(@".\" + dt_s + ".txt", "\t");

        QRCodeInputImage = new Bitmap(f.FullName,true);

        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]);

        //ビジネスロジック  
        //string str1 = Result.Replace("ω", " ");
        //str1 = str1.Replace("Ω", "\t");
        string str1 = Result;

        System.IO.File.AppendAllText(@".\" + dt_s + ".txt", str1);
        System.IO.File.AppendAllText(@".\" + dt_s + ".txt", Environment.NewLine);

    }

 }

}

注:
集めるファイルがtifではなく、jpgの場合は、
途中の、GetFilesで読んでいるファイルを
".tif"を、".jpg"にするだけでよいと思います

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