簡體   English   中英

解碼圖像時出錯

[英]Error when decoding image

我正在嘗試使用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.";
        }
    }

ERROR1:

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:如果有人對此MessagingToolkit QR軟件包有文檔,這將非常有用

解碼接受“位圖”類型的圖像。

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
                        }

另外,您還可以省略“ decodingOptions”選項參數,因為解碼器還具有重載的Decode(位圖圖像​​)。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM