|
|
@@ -7,7 +7,6 @@ import com.google.zxing.common.HybridBinarizer;
|
|
|
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
-import java.awt.*;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
|
@@ -21,7 +20,7 @@ import java.util.Map;
|
|
|
* @author reghao
|
|
|
* @date 2023-12-22 16:39:04
|
|
|
*/
|
|
|
-public class ImageUtil {
|
|
|
+public class QRCode {
|
|
|
public static ByteArrayOutputStream createQRCode(String content, int width, int height) throws WriterException, IOException {
|
|
|
Hashtable<EncodeHintType, Object> hints = new Hashtable<>();
|
|
|
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
|
|
|
@@ -51,29 +50,4 @@ public class ImageUtil {
|
|
|
Result result = new MultiFormatReader().decode(binaryBitmap, hints);
|
|
|
return result.getText();
|
|
|
}
|
|
|
-
|
|
|
- public static ByteArrayOutputStream createImage(String text, int width, int height) throws IOException {
|
|
|
- // 得到图片缓冲区
|
|
|
- BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
|
|
|
- // 获取绘制环境
|
|
|
- Graphics2D g2d = (Graphics2D)bi.getGraphics();
|
|
|
- // 设置背景色
|
|
|
- g2d.setColor(Color.WHITE);
|
|
|
- //填冲一个矩形
|
|
|
- g2d.fillRect(0, 0, width, height);
|
|
|
- //给图片加边框
|
|
|
- g2d.setColor(Color.RED);
|
|
|
- g2d.drawRect(0, 0, width-1, height-1);
|
|
|
- String fontName = "WenQuanYi Micro Hei";
|
|
|
- int fontSize = 18;
|
|
|
- g2d.setFont(new Font(fontName, Font.PLAIN, fontSize));
|
|
|
- //设置颜色
|
|
|
- g2d.setColor(Color.RED);
|
|
|
- //向图片中写字符串
|
|
|
- g2d.drawString(text, 5, 29);
|
|
|
-
|
|
|
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
- ImageIO.write(bi, "jpg", byteArrayOutputStream);
|
|
|
- return byteArrayOutputStream;
|
|
|
- }
|
|
|
}
|