2

私はMessagingToolkitを使用してC#/ASP.NETの画像をデコードしようとしています。このパッケージを使用してqrをエンコードすることができましたが、デコードしようとすると、以下のコードを使用すると2つのエラーが発生します(ページの下部にあります)

これは、アップロード後に画像が正しく取得されていないためだと思いますが、どこが間違っているのかを誰かが正確に指摘できます。ありがとう。

    protected void CreateCode_OnClick(object sender, EventArgs e)
    {
        string path = "C:\\Users\\Wayneio\\Documents\\Visual Studio 2012\\Projects\\BAMSystem\\BAMSystem\\";
        if (QRUpload.HasFiles == true)
        {
            FileInfo fi = new FileInfo(QRUpload.FileName);
            string extA = fi.Extension;
            if (extA == ".jpg" || extA == ".png")
            {
               QRCodeDecoder decoder = new QRCodeDecoder();
               QRUpload.SaveAs(path + QRUpload.FileName);

               System.Drawing.Image myImg = System.Drawing.Image.FromFile(path + QRUpload.FileName);
               decoder.Decode(myImg);

            }
            else
            {
                error.Text = "You have uploaded a " + extA + " file. Please upload either a PNG or a JPG";
            }
        }
        else
        {
            error.Text = "You have not uploaded an image.";
        }
    }

エラー1:

Error   2   Argument 1: cannot convert from 'System.Drawing.Image' to 'MessagingToolkit.QRCode.Codec.Data.QRCodeImage'  c:\users\wayneio\documents\visual studio 2012\Projects\BAMSystem\BAMSystem\default.aspx.cs  38  35  BAMSystem

エラー2:

Error   1   The best overloaded method match for 'MessagingToolkit.QRCode.Codec.QRCodeDecoder.Decode(MessagingToolkit.QRCode.Codec.Data.QRCodeImage)' has some invalid arguments    c:\users\wayneio\documents\visual studio 2012\Projects\BAMSystem\BAMSystem\default.aspx.cs  38  20  BAMSystem

PS誰かがこのMessagingToolkitQRパッケージに関するドキュメントを持っているなら、それは役に立ちます

4

1 に答える 1

1

デコードは「ビットマップ」タイプの画像を受け入れます。

System.Drawing.Bitmap myImg = new System.Drawing.Bitmap(FileName);
Dictionary<DecodeOptions, object> decodingOptions = new Dictionary<DecodeOptions, object>();
List<BarcodeFormat> possibleFormats = new List<BarcodeFormat>(10);

                        possibleFormats.Add(BarcodeFormat.DataMatrix);
                        possibleFormats.Add(BarcodeFormat.QRCode);
                        possibleFormats.Add(BarcodeFormat.PDF417);
                        possibleFormats.Add(BarcodeFormat.Aztec);
                        possibleFormats.Add(BarcodeFormat.UPCE);
                        possibleFormats.Add(BarcodeFormat.UPCA);
                        possibleFormats.Add(BarcodeFormat.Code128);
                        possibleFormats.Add(BarcodeFormat.Code39);
                        possibleFormats.Add(BarcodeFormat.ITF14);
                        possibleFormats.Add(BarcodeFormat.EAN8);
                        possibleFormats.Add(BarcodeFormat.EAN13);
                        possibleFormats.Add(BarcodeFormat.RSS14);
                        possibleFormats.Add(BarcodeFormat.RSSExpanded);
                        possibleFormats.Add(BarcodeFormat.Codabar);
                        possibleFormats.Add(BarcodeFormat.MaxiCode);

 decodingOptions.Add(DecodeOptions.TryHarder, true);
 decodingOptions.Add(DecodeOptions.PossibleFormats, possibleFormats);
Result decodedResult = decoder.Decode(myImg, decodingOptions);

          if (decodedResult != null)
                        {
                          //.. success
                        }

また、デコーダーにはオーバーロードDecode(Bitmap image)もあるため、「decodingOptions」オプションパラメーターを省略できます。

System.Drawing.Bitmap myImg = new System.Drawing.Bitmap(FileName);
Result decodedResult = decoder.Decode(myImg);

          if (decodedResult != null)
                        {
                          //.. success
                        }

QRCodeのデコードのみが必要な場合は、

    System.Drawing.Bitmap myImg = new System.Drawing.Bitmap(FileName);
    Dictionary<DecodeOptions, object> decodingOptions = new Dictionary<DecodeOptions, object>();
    List<BarcodeFormat> possibleFormats = new List<BarcodeFormat>();
    possibleFormats.Add(BarcodeFormat.QRCode);                              
    decodingOptions.Add(DecodeOptions.TryHarder, true);
    decodingOptions.Add(DecodeOptions.PossibleFormats, possibleFormats);
    Result decodedResult = decoder.Decode(myImg, decodingOptions);
     if (decodedResult != null)
       {
          //.. success
       }

ドキュメントとコードはここ
http://platform.twit88.com/projects/show/mt-barcodeにあります。

サンプルコード..ここからダウンロード..デモコードもあります
http://platform.twit88.com/projects/mt-barcode/files

ここでのコードプロジェクト
http://www.codeproject.com/Articles/20574/Open-Source-QRCode-Library

于 2012-10-24T19:47:42.310 に答える