Max*_*sky 8 c# java barcode zxing
注意:我最初的问题是关于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();
Run Code Online (Sandbox Code Playgroud)
我在以"Result result = ..."开头的行上遇到异常ReaderException指出: "Unable to cast object of type 'com.google.zxing.oned.MultiFormatOneDReader' to type 'com.google.zxing.Reader'.
那么,我做错了什么?
更新:我将尝试建议的想法,但与此同时,我在ZXing小组中发现了这个问题.
小智 11
这是生成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);
Run Code Online (Sandbox Code Playgroud)
请参阅http://code.google.com/p/zxing/wiki/BarcodeContents上的条形码格式
我怀疑您只是缺少演员/使用了错误的类型,请尝试更改
Result result = reader.decode(image);
Run Code Online (Sandbox Code Playgroud)
插入以下内容之一
Result result = (Result)reader.decode(image);
Run Code Online (Sandbox Code Playgroud)
或者可能
MultiFormatOneDResult result = reader.decode(image);
Run Code Online (Sandbox Code Playgroud)
恐怕我现在无法访问 ac# 编译器,所以我无法验证这一点 - 所以如果我偏离了目标,我深表歉意!
| 归档时间: |
|
| 查看次数: |
20443 次 |
| 最近记录: |