I use the following code to generate a QR code image.
----------------------------------------------------------------
String content = "test123中文" ;
Hashtable hints = new Hashtable();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
QRCode qrCode = new QRCode();
Encoder.encode(content, ErrorCorrectionLevel.M, hints, qrCode);
ByteMatrix matrix = renderResult(qrCode, 256, 256) ; //this method
is copy from the QRCodeWriter class
BufferedImage image = createImageFromMatrix(matrix) ; // this method
is definded as below
File imageFile = new File("F:\\temp\\test.png") ;
ImageIO.write(image,"PNG",imageFile) ;
----------------------------------------------------------------
private static BufferedImage createImageFromMatrix(ByteMatrix matrix)
throws Exception {
int width = matrix.width() ;
int hight = matrix.height() ;
BufferedImage image = new BufferedImage(width, hight,
BufferedImage.TYPE_INT_RGB) ;
for(int x=0;x<width;x++){
for(int y=0;y<hight;y++){
image.setRGB(x,y,matrix.get(y,x));
}
}
return image ;
}
----------------------------------------------------------------
And I got this image:
http://zfkhrl.googlepages.com/test.png
=========================================
When I use the following code to decode this image:
-------------------------------------------
QRCodeReader reader = new QRCodeReader() ;
MonochromeBitmapSource image = new
BufferedImageMonochromeBitmapSource(ImageIO.read(new File("F:\\temp\
\test.png"))) ;
Result result = reader.decode(image) ;
String decodeString = result.getText() ;
System.out.println(decodeString);
--------------------------------------------
The code throw a ReaderException, and the image can not be read by
other desktop QR code decode software too.
I appriciate any help you can provide to my problem. Thank you.
On 5月26日, 下午7时09分, srowen <
sro...@gmail.com> wrote:
> Can you send the QR Code so I can debug? it should work -- if not
> there is a bug somewhere.
>
> On May 26, 11:11 am,
zfk...@gmail.com wrote:
>
>
>
> > The codes:
> > -------------------------------------------------------
> > Hashtable hints = new Hashtable();
> > hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
> > QRCode qrCode = new QRCode();
> > Encoder.encode(yourString, ErrorCorrectionLevel.M, hints, qrCode);
> > --------------------------------------------------------------------------------------------------
> > is not work for me, I try that before I post my question.
> > The generated QRcode image looks like a QRcode, with black and white
> > blocks, but it can not be decoded by zxing, the code throw an
> > Exception.
>
> > It seems in the Encoder.encode(), the append ECI code has been
> > commented. I uncomment the code, still not working.- 隐藏被引用文字 -
>
> - 显示引用的文字 -