gpt4 book ai didi

c# - 解码图像时出错

转载 作者:太空宇宙 更新时间:2023-11-03 13:53:26 25 4
gpt4 key购买 nike

我正在尝试使用 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

P.S 如果有人有关于这个 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(Bitmap image)。

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

关于c# - 解码图像时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13056484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com