|
@@ -1,10 +1,9 @@
|
|
|
package cn.reghao.tnb.file.app.util;
|
|
package cn.reghao.tnb.file.app.util;
|
|
|
|
|
|
|
|
-import com.google.zxing.BarcodeFormat;
|
|
|
|
|
-import com.google.zxing.EncodeHintType;
|
|
|
|
|
-import com.google.zxing.MultiFormatWriter;
|
|
|
|
|
-import com.google.zxing.WriterException;
|
|
|
|
|
|
|
+import com.google.zxing.*;
|
|
|
|
|
+import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
|
|
|
import com.google.zxing.common.BitMatrix;
|
|
import com.google.zxing.common.BitMatrix;
|
|
|
|
|
+import com.google.zxing.common.HybridBinarizer;
|
|
|
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
|
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
|
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
import javax.imageio.ImageIO;
|
|
@@ -12,8 +11,11 @@ import java.awt.*;
|
|
|
import java.awt.image.BufferedImage;
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
|
+import java.io.InputStream;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.Hashtable;
|
|
import java.util.Hashtable;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author reghao
|
|
* @author reghao
|
|
@@ -38,6 +40,18 @@ public class ImageUtil {
|
|
|
return byteArrayOutputStream;
|
|
return byteArrayOutputStream;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public String decodeQRCode(InputStream in) throws IOException, NotFoundException {
|
|
|
|
|
+ BufferedImage bi = ImageIO.read(in);
|
|
|
|
|
+ LuminanceSource source = new BufferedImageLuminanceSource(bi);
|
|
|
|
|
+ Binarizer binarizer = new HybridBinarizer(source);
|
|
|
|
|
+ BinaryBitmap binaryBitmap = new BinaryBitmap(binarizer);
|
|
|
|
|
+
|
|
|
|
|
+ Map<DecodeHintType, String> hints = new HashMap<>();
|
|
|
|
|
+ hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
|
|
|
|
|
+ Result result = new MultiFormatReader().decode(binaryBitmap, hints);
|
|
|
|
|
+ return result.getText();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public static ByteArrayOutputStream createImage(String text, int width, int height) throws IOException {
|
|
public static ByteArrayOutputStream createImage(String text, int width, int height) throws IOException {
|
|
|
// 得到图片缓冲区
|
|
// 得到图片缓冲区
|
|
|
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
|
|
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
|