如何使用ZXing C#港口 [英] How To Use ZXing C# Port

查看:148
本文介绍了如何使用ZXing C#港口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注:我原来的问题是是否斑马线C#端口是可靠的,但在这里,我想弄清楚如何使用它。因此,它们不重复。

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.

我试图使用 ZXing C#模块,但我有麻烦了。请问谁使用ZXing才有人知道如何正确地做到这一点?不幸的是,C#文档是相当小的。

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.

我目前的code是:

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();

我得到在该行开头的异常结果结果= ...的ReaderException规定:无法投类型的对象'com.google.zxing.oned.MultiFormatOneDReader 键入com.google.zxing.Reader。

那么,我究竟做错了什么?

So, what am I doing wrong?

更新:我要去尝试建议的想法,但在此期间,我发现这个<一个href=\"http://groups.google.com/group/zxing/browse%5Fthread/thread/d481685e6b46c528/d27d9e46e218ce6f?lnk=gst&q=c%23#d27d9e46e218ce6f\">issue在斑马线组。

UPDATE: I'm going to try the suggested ideas, but in the meantime, I found this issue in the ZXing group.

推荐答案

这是生成QR code的样本。

This is a sample to generate a 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);

看到了吧code画幅的<一个href=\"http://$c$c.google.com/p/zxing/wiki/Bar$c$cContents\">http://$c$c.google.com/p/zxing/wiki/Bar$c$cContents

这篇关于如何使用ZXing C#港口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆