如何使用ZXing C#端口

如何使用ZXing C#端口,c#,java,barcode,zxing,C#,Java,Barcode,Zxing,注意:关于ZXing C#port是否可靠的问题,但在这里,我试图找出如何使用它。因此,它们不是重复的 我正在尝试使用C#模块,但遇到了问题。以前使用过ZXing的人知道如何正确使用它吗?不幸的是,C#文档非常小 我目前的代码是: using com.google.zxing; using com.google.zxing.client.j2se; using com.google.zxing.common; //... Reader reader = new MultiFormatRead

注意:关于ZXing C#port是否可靠的问题,但在这里,我试图找出如何使用它。因此,它们不是重复的

我正在尝试使用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.multiformatoneReader'类型的对象强制转换为'com.google.zxing.Reader'。

那么,我做错了什么


更新:我将尝试建议的想法,但与此同时,我在中兴集团中发现了这一点。

我怀疑您只是缺少演员阵容/使用了错误的类型,请尝试更改

Result result = reader.decode(image);
排队进入以下选项之一

Result result = (Result)reader.decode(image);
或者可能

MultiFormatOneDResult result = reader.decode(image);

恐怕我现在无法访问c#编译器,因此我无法验证这一点-因此,如果我偏离了目标,我很抱歉!

我认为这一定是端口中的缺陷,因为在原始Java中,这些类是强制转换兼容的。也许只是在代码中使用MultiformatoneReader作为引用类型,而不是Reader,尽管line本来应该很好。如果您修复了源代码并希望提交更改,请让我们(项目)知道。

这是生成QRCode的示例

        QRCodeWriter writer = new QRCodeWriter();
        com.google.zxing.common.ByteMatrix matrix;

        int size = 180;
        matrix = writer.encode("MECARD:N:Owen,Sean;ADR:76 9th Avenue, 4th Floor, New York, NY 10011;TEL:+12125551212;EMAIL:srowen@example.com;; ", BarcodeFormat.QR_CODE, size, size, null);


        Bitmap img = new Bitmap(size, size);
        Color Color = Color.FromArgb(0, 0, 0);

        for (int y = 0; y < matrix.Height; ++y)
        {
            for (int x = 0; x < matrix.Width; ++x)
            {
                Color pixelColor = img.GetPixel(x, y);

                //Find the colour of the dot
                if (matrix.get_Renamed(x, y) == -1)
                {
                    img.SetPixel(x, y, Color.White );
                }
                else
                {
                    img.SetPixel(x, y, Color.Black);
                }
            }
        }


        img.Save(@"c:\test.bmp",ImageFormat.Bmp);
QRCodeWriter writer=新的QRCodeWriter();
com.google.zxing.common.ByteMatrix矩阵;
int size=180;
matrix=writer.encode(“MECARD:N:Owen,Sean;ADR:76纽约州纽约市第九大道4楼,邮编10011;电话:+12125551212;电子邮件:srowen@example.com;;”,条形码格式。QR_代码,大小,大小,空);
位图img=新位图(大小、大小);
Color Color=Color.FromArgb(0,0,0);
对于(int y=0;y

请参见

中的条形码格式问题是关于读取条形码,而不是创建条形码,因此主题错误,但回答不错:)