色欲av一区久久精品_久久综合色综合色88_无码在线观看不卡_色黄视频网站_亚洲国产精品久久久久秋霞66

java Springboot 生成 二維碼 +logo

時間:2023-05-17

上碼,如有問題或者優(yōu)化,勞請廣友下方留言
1.工具類
復制代碼
importcom.google.zxing.BarcodeFormat;
importcom.google.zxing.EncodeHintType;
importcom.google.zxing.client.j2se.MatrixToImageConfig;
importcom.google.zxing.client.j2se.MatrixToImageWriter;
importcom.google.zxing.common.BitMatrix;
importcom.google.zxing.qrcode.QRCodeWriter;
importcom.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
importcom.sun.org.apache.xml.internal.security.utils.Base64;
importorg.springframework.util.ResourceUtils;
importjavax.imageio.ImageIO;
importjavax.servlet.ServletOutputStream;
importjava.awt.*;
importjava.awt.geom.RoundRectangle2D;
importjava.awt.image.BufferedImage;
importjava.io.ByteArrayOutputStream;
importjava.io.FileOutputStream;
importjava.io.IOException;
importjava.io.OutputStream;
importjava.util.HashMap;
publicclassQrCodeUtil{
publicStringcreateQRCode(Stringcontent,intwidth,intheight,Stringpath)throwsIOException{
StringresultImage=””;
if(!EmptyUtils.isEmpty(content)){
ServletOutputStreamstream=null;
ByteArrayOutputStreamos=newByteArrayOutputStream();
@SuppressWarnings(“rawtypes”)
HashMap<EncodeHintType,Comparable>hints=newHashMap<>();
hints.put(EncodeHintType.CHARACTER_SET,”utf-8″);//指定字符編碼為“utf-8”
hints.put(EncodeHintType.ERROR_CORRECTION,ErrorCorrectionLevel.M);//指定二維碼的糾錯等級為中
hints.put(EncodeHintType.MARGIN,2);//指定二維碼邊距java
try{
QRCodeWriterwriter=newQRCodeWriter();
BitMatrixbitMatrix=writer.encode(content,BarcodeFormat.QR_CODE,width,height,hints);
MatrixToImageConfigconfig=newMatrixToImageConfig(0xFF000001,0xFFFFFFFF);
BufferedImagebufferedImage=MatrixToImageWriter.toBufferedImage(bitMatrix,config);
//BufferedImagebufferedImage=newBufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
//for(intx=0;x<width;x++){
//for(inty=0;y<height;y++){
//bufferedImage.setRGB(x,y,bitMatrix.get(x,y)?0xFF000000:0xFFFFFFFF);
//}
//}
Graphics2Dg2=bufferedImage.createGraphics();
g2.drawImage(ImageIO.read(ResourceUtils.getFile(path)),width/5*2,height/5*2,width/5,height/5,null);//logo.png自行設置
g2.setStroke(newBasicStroke(5,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
g2.draw(newRoundRectangle2D.Float(width/5*2,height/5*2,width/5,height/5,20,20));
g2.dispose();
g2.setColor(Color.white);
g2.setBackground(Color.white);
bufferedImage.flush();
ImageIO.write(bufferedImage,”png”,os);
OutputStreamout=newFileOutputStream(“D:\\logo\\abb.png”);
out.write(os.toByteArray());
resultImage=newString(“data:image/png;base64,”+Base64.encode(os.toByteArray()));
returnresultImage;
}catch(Exceptione){
e.printStackTrace();
}finally{
if(stream!=null){
stream.flush();
stream.close();
}
}
}
returnnull;
}
}

文章標簽:

Copyright ? 2016 廣州思洋文化傳播有限公司,保留所有權利。 粵ICP備09033321號

與項目經(jīng)理交流
掃描二維碼
與項目經(jīng)理交流
掃描二維碼
與項目經(jīng)理交流
ciya68