简体   繁体   English

解码图像时出错

[英]Error when decoding image

I am trying to use MessagingToolkit to decode an image in C#/ASP.NET. 我正在尝试使用MessagingToolkit解码C#/ ASP.NET中的图像。 I have managed to encode a qr using this package, but when i try to decode, using the code below it comes up with 2 errors (at the bottom of the page) 我已经设法使用此程序包对一个qr进行编码,但是当我尝试解码时,使用下面的代码会出现2个错误(在页面底部)

I believe this is because I am not getting the image correctly after uploading, but can someone point out exactly where I have gone wrong. 我相信这是因为上传后我无法正确获取图像,但是有人可以指出我出了什么问题。 Thanks. 谢谢。

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

Error2: 误差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 if anyone has documentation on this MessagingToolkit QR package, it would be useful PS:如果有人对此MessagingToolkit QR软件包有文档,这将非常有用

Decode accepts 'Bitmap' type image. 解码接受“位图”类型的图像。

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
                        }

Also you can also omit the "decodingOptions" options parameter as decoder also has an overload Decode(Bitmap image). 另外,您还可以省略“ decodingOptions”选项参数,因为解码器还具有重载的Decode(位图图像​​)。

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

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

If you want only QRCode decoding, 如果您只想要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
       }

You can find documentation and code here 您可以在此处找到文档和代码
http://platform.twit88.com/projects/show/mt-barcode http://platform.twit88.com/projects/show/mt-barcode

Sample code ..download here ..has demo code also 示例代码..在这里下载..还有演示代码
http://platform.twit88.com/projects/mt-barcode/files http://platform.twit88.com/projects/mt-barcode/files

Code project here 这里的代码项目
http://www.codeproject.com/Articles/20574/Open-Source-QRCode-Library http://www.codeproject.com/Articles/20574/Open-Source-QRCode-Library

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM