如何使用ZXing C#端口
注意:我最初的问题是关于 ZXing C# 端口是否可靠,但在这里,我想弄清楚如何使用它。因此,它们不是重复的。
我正在尝试使用 ZXing C# 模块,但我遇到了麻烦。有使用过ZXing的人知道如何正确操作吗?不幸的是,C# 文档非常小。
我当前的代码是:
using com.google.zxing;
using com.google.zxing.client.j2se;
using com.google.zxing.common;
//...
Reader reader = new MultiFormatReader();
MonochromeBitmapSource image = new BufferedImageMonochromeBitmapSource(new Bitmap(Image.FromFile("barcode.jpg")),false);
Result result = reader.decode(image);
string text = result.getText();
sbyte[] rawbytes = result.getRawBytes();
BarcodeFormat format = result.getBarcodeFormat();
ResultPoint[] points = result.getResultPoints();
Console.WriteLine("barcode text: {0}", text);
Console.WriteLine("raw bytes: {0}", rawbytes);
Console.WriteLine("format: {0}", format);
Console.ReadLine();
我在以“Result result = ...”开头的行上遇到异常 ReaderException 状态: “无法转换类型为 'com.google.zxing.oned.MultiFormatOneDReader' 的对象输入“com.google.zxing.Reader”。
那么,我做错了什么
更新:我将尝试建议的想法,但与此同时,我发现此问题 在 ZXing 组中。
NOTE: My original question was about whether the ZXing C# port is reliable, but here, I'm trying to figure out how to use it. Thus, they are not duplicates.
I'm trying to use the ZXing C# module, but I'm having trouble. Does anyone who has used ZXing before know how to do it correctly? Unfortunately, the C# documentation is quite small.
My current code is:
using com.google.zxing;
using com.google.zxing.client.j2se;
using com.google.zxing.common;
//...
Reader reader = new MultiFormatReader();
MonochromeBitmapSource image = new BufferedImageMonochromeBitmapSource(new Bitmap(Image.FromFile("barcode.jpg")),false);
Result result = reader.decode(image);
string text = result.getText();
sbyte[] rawbytes = result.getRawBytes();
BarcodeFormat format = result.getBarcodeFormat();
ResultPoint[] points = result.getResultPoints();
Console.WriteLine("barcode text: {0}", text);
Console.WriteLine("raw bytes: {0}", rawbytes);
Console.WriteLine("format: {0}", format);
Console.ReadLine();
I'm getting an exception on the line that starts with "Result result = ..." The ReaderException states: "Unable to cast object of type 'com.google.zxing.oned.MultiFormatOneDReader' to type 'com.google.zxing.Reader'.
So, what am I doing wrong?
UPDATE: I'm going to try the suggested ideas, but in the meantime, I found this issue in the ZXing group.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是生成 QRCode 的示例。
请访问 http://code.google.com/p/zxing/wiki/BarcodeContents 查看条形码格式
This is a sample to generate a QRCode.
See the Barcode format at http://code.google.com/p/zxing/wiki/BarcodeContents
我认为这一定是移植中的缺陷,因为在原始 Java 中这些类是强制转换兼容的。也许只是使用 MultiFormatOneDReader 作为代码中的引用类型而不是 Reader,尽管该行应该按原样就好。如果您以其他方式修复源并想要提交更改,请告诉我们(项目)。
I think that must be a deficiency in the port, since in the original Java these classes are cast-compatible. Perhaps just use MultiFormatOneDReader as the reference type in the code rather than Reader, though the line should have been fine as-is. If you otherwise fix the source and want to submit the change let us (the project) know.
我怀疑您只是缺少强制转换/使用了错误的类型,请尝试将
行更改为以下之一
,或者可能
我担心我现在无法访问 ac# 编译器,所以我无法验证这一点- 所以如果我偏离了目标,我深表歉意!
I suspect you are just missing a cast/are using the wrong type, try changing
line in to one of the following
or possibly
I'm afraid I don't have access to a c# compiler right now, so I can't verify this - so I apologise if I'm way off the mark!