8

注:私の最初の質問は、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 は次のように述べています。"Unable to cast object of type 'com.google.zxing.oned.MultiFormatOneDReader' to type 'com.google.zxing.Reader'.

それで、私は何を間違っていますか?

更新:提案されたアイデアを試すつもりですが、それまでの間、ZXing グループでこの問題を見つけました。

4

3 に答える 3

11

QRコードを生成するサンプルです。

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

http://code.google.com/p/zxing/wiki/BarcodeContentsでバーコード形式を参照してください。

于 2011-09-01T14:41:32.947 に答える
2

元のJavaではこれらのクラスはキャスト互換であるため、これはポートの欠陥に違いないと思います。おそらく、Reader ではなくコード内の参照型として MultiFormatOneDReader を使用するだけですが、この行はそのままで問題ないはずです。他の方法でソースを修正し、変更を送信したい場合は、私たち (プロジェクト) に知らせてください。

于 2009-11-01T01:10:25.620 に答える
1

キャストが欠落している/間違ったタイプを使用していると思われます。変更してみてください

Result result = reader.decode(image);

次のいずれかに行

Result result = (Result)reader.decode(image);

またはおそらく

MultiFormatOneDResult result = reader.decode(image);

残念ながら、私は現在 ac# コンパイラにアクセスできないため、これを確認することはできません。

于 2009-11-01T00:55:12.750 に答える