当前位置: 首页 > news >正文

Java中生成指定字体的印章

文章目录

  • 1.引入字体
    • 2.Windows环境下
    • 3. Linux环境下
  • 生成印章
  • 测试类
  • 绘制方章
  • 测试类

1.引入字体

2.Windows环境下

在这里插入图片描述
在这里插入图片描述如果在Windows上安装JAVA环境时,没有安装单独的jre1.8.0_141的话。那么字体就只放到\jdk1.8.0_141\jre\lib\fonts目前下。

3. Linux环境下

cat /etc/profile
在这里插入图片描述
找到上方的JAVA_HOME路径
[root@iZ2zeddfx87fxxx4m4dlxu8dZ fonts]# pwd #进入以下目录下
/home/jdk/jdk1.8.0_181/jre/lib/fonts
[root@iZ2zeddfx87fxxx4m4dlxu8dZ fonts]# mkdir fallback #创建一个空目录,用于放置外部字体
在这里插入图片描述
然后执行
[root@iZ2zeddfx87fw4m4dlxu8dZ fallback]# mkfontscale #不知道不执行是否可以
[root@iZ2zeddfx87fw4m4dlxu8dZ fallback]# mkfontdir #这个必须执行
在这里插入图片描述
这样就在fallback目录下多出了两个文件。注意不执行上方的mkfontscale和mkfontdir。即使把字体放到了指定的fonts目录下了。在CentOS下使用字体也会找不到的。会使用其他默认字体代替。这一点和Window上的不同。
我们可以通过比较两者fonts目录下的文件可以发现。
在这里插入图片描述

生成印章

Seal类代码:

package cn.com.yuanquanyun.bjca_scan;import lombok.Builder;
import lombok.Getter;
import org.springframework.util.ResourceUtils;import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.font.FontRenderContext;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;@Getter
@Builder
public class Seal {// 起始位置private static final int INIT_BEGIN = 5;// 尺寸private Integer size;// 颜色private Color color;// 主字private SealFont mainFont;// 副字private SealFont viceFont;// 抬头private SealFont titleFont;// 中心字private SealFont centerFont;// 边线圆private SealCircle borderCircle;// 内边线圆private SealCircle borderInnerCircle;// 内线圆private SealCircle innerCircle;// 边线框private Integer borderSquare;// 加字private String stamp;/*** 画公章*/public byte[] draw(String imgFmt) throws Exception {if (borderSquare != null) {return draw2(imgFmt); // 画私章}//1.画布BufferedImage bi = new BufferedImage(size, size, BufferedImage.TYPE_4BYTE_ABGR);//2.画笔Graphics2D g2d = bi.createGraphics();//2.1抗锯齿设置//文本不抗锯齿,否则圆中心的文字会被拉长RenderingHints hints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);//其他图形抗锯齿hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);g2d.setRenderingHints(hints);//2.2设置背景透明度g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 0));//2.3填充矩形g2d.fillRect(0, 0, size, size);//2.4重设透明度,开始画图g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 1));//2.5设置画笔颜色g2d.setPaint(color == null ? Color.RED : color);//3.画边线圆if (borderCircle != null) {drawCircle(g2d, borderCircle, INIT_BEGIN, INIT_BEGIN);} else {throw new Exception("BorderCircle can not null!");}int borderCircleWidth = borderCircle.getWidth();int borderCircleHeight = borderCircle.getHeight();//4.画内边线圆if (borderInnerCircle != null) {int x = INIT_BEGIN + borderCircleWidth - borderInnerCircle.getWidth();int y = INIT_BEGIN + borderCircleHeight - borderInnerCircle.getHeight();drawCircle(g2d, borderInnerCircle, x, y);}//5.画内环线圆if (innerCircle != null) {int x = INIT_BEGIN + borderCircleWidth - innerCircle.getWidth();int y = INIT_BEGIN + borderCircleHeight - innerCircle.getHeight();drawCircle(g2d, innerCircle, x, y);}//6.画弧形主文字if (borderCircleHeight != borderCircleWidth) {drawArcFont4Oval(g2d, borderCircle, mainFont, true);} else {drawArcFont4Circle(g2d, borderCircleHeight, mainFont, true);}//7.画弧形副文字if (borderCircleHeight != borderCircleWidth) {drawArcFont4Oval(g2d, borderCircle, viceFont, false);} else {drawArcFont4Circle(g2d, borderCircleHeight, viceFont, false);}//8.画中心字drawFont(g2d, (borderCircleWidth + INIT_BEGIN) * 2, (borderCircleHeight + INIT_BEGIN) * 2, centerFont);//9.画抬头文字drawFont(g2d, (borderCircleWidth + INIT_BEGIN) * 2, (borderCircleHeight + INIT_BEGIN) * 2, titleFont);g2d.dispose();//ByteArrayOutputStream outputStream = new ByteArrayOutputStream();boolean png = ImageIO.write(bi, imgFmt, outputStream);byte[] imgBytes = outputStream.toByteArray();outputStream.flush();outputStream.close();return imgBytes;}public byte[] draw(String pngPath,String imgFmt) throws Exception {//如果只是生成印章字节数组,不进行输出的话,传入的pngPath,无用byte[] imgBytes = draw(imgFmt);return imgBytes;
//        FileOutputStream fileOutputStream = new FileOutputStream(new File(pngPath));
//        fileOutputStream.write(imgBytes);}/*** 绘制圆弧形文字*/private static void drawArcFont4Circle(Graphics2D g2d, int circleRadius, SealFont font, boolean isTop) throws IOException, FontFormatException {if (font == null) {return;}//1.字体长度int textLen = font.getText().length();//2.字体大小,默认根据字体长度动态设定int size = font.getSize() == null ? (55 - textLen * 2) : font.getSize();//3.字体样式int style = font.getBold() ? Font.BOLD : Font.PLAIN;//4.构造字体//      Font f = new Font(font.getFamily(), style, size);//默认从JRE中的fonts目录下读取//File file = new File("config/font/gzkzzt.ttf");//如果如CSDN上方描述的那样已经把字体放到jre下了。这里就不用写死指定了
//        System.out.println("已读取字体文件");Font f = Font.createFont(Font.TRUETYPE_FONT, file);f = f.deriveFont(style,size);FontRenderContext context = g2d.getFontRenderContext();Rectangle2D rectangle = f.getStringBounds(font.getText(), context);//5.文字之间间距,默认动态调整double space;if (font.getSpace() != null) {space = font.getSpace();} else {if (textLen == 1) {space = 0;} else {space = rectangle.getWidth() / (textLen - 1) * 0.9;}}//6.距离外圈距离int margin = font.getMargin() == null ? INIT_BEGIN : font.getMargin();//7.写字double newRadius = circleRadius + rectangle.getY() - margin;double radianPerInterval = 2 * Math.asin(space / (2 * newRadius));double fix = 0.04;if (isTop) {fix = 0.18;}double firstAngle;if (!isTop) {if (textLen % 2 == 1) {firstAngle = Math.PI + Math.PI / 2 - (textLen - 1) * radianPerInterval / 2.0 - fix;} else {firstAngle = Math.PI + Math.PI / 2 - ((textLen / 2.0 - 0.5) * radianPerInterval) - fix;}} else {if (textLen % 2 == 1) {firstAngle = (textLen - 1) * radianPerInterval / 2.0 + Math.PI / 2 + fix;} else {firstAngle = (textLen / 2.0 - 0.5) * radianPerInterval + Math.PI / 2 + fix;}}for (int i = 0; i < textLen; i++) {double theta;double thetaX;double thetaY;if (!isTop) {theta = firstAngle + i * radianPerInterval;thetaX = newRadius * Math.sin(Math.PI / 2 - theta);thetaY = newRadius * Math.cos(theta - Math.PI / 2);} else {theta = firstAngle - i * radianPerInterval;thetaX = newRadius * Math.sin(Math.PI / 2 - theta);thetaY = newRadius * Math.cos(theta - Math.PI / 2);}AffineTransform transform;if (!isTop) {transform = AffineTransform.getRotateInstance(Math.PI + Math.PI / 2 - theta);} else {transform = AffineTransform.getRotateInstance(Math.PI / 2 - theta + Math.toRadians(8));}Font f2 = f.deriveFont(transform);g2d.setFont(f2);g2d.drawString(font.getText().substring(i, i + 1), (float) (circleRadius + thetaX + INIT_BEGIN), (float) (circleRadius - thetaY + INIT_BEGIN));}}/*** 绘制椭圆弧形文字*/private static void drawArcFont4Oval(Graphics2D g2d, SealCircle sealCircle, SealFont font, boolean isTop) {if (font == null) {return;}float radiusX = sealCircle.getWidth();float radiusY = sealCircle.getHeight();float radiusWidth = radiusX + sealCircle.getLine();float radiusHeight = radiusY + sealCircle.getLine();//1.字体长度int textLen = font.getText().length();//2.字体大小,默认根据字体长度动态设定int size = font.getSize() == null ? 25 + (10 - textLen) / 2 : font.getSize();//3.字体样式int style = font.getBold() ? Font.BOLD : Font.PLAIN;//4.构造字体Font f = new Font(font.getFamily(), style, size);//5.总的角跨度double totalArcAng = font.getSpace() * textLen;//6.从边线向中心的移动因子float minRat = 0.90f;double startAngle = isTop ? -90f - totalArcAng / 2f : 90f - totalArcAng / 2f;double step = 0.5;int alCount = (int) Math.ceil(totalArcAng / step) + 1;double[] angleArr = new double[alCount];double[] arcLenArr = new double[alCount];int num = 0;double accArcLen = 0.0;angleArr[num] = startAngle;arcLenArr[num] = accArcLen;num++;double angR = startAngle * Math.PI / 180.0;double lastX = radiusX * Math.cos(angR) + radiusWidth;double lastY = radiusY * Math.sin(angR) + radiusHeight;for (double i = startAngle + step; num < alCount; i += step) {angR = i * Math.PI / 180.0;double x = radiusX * Math.cos(angR) + radiusWidth, y = radiusY * Math.sin(angR) + radiusHeight;accArcLen += Math.sqrt((lastX - x) * (lastX - x) + (lastY - y) * (lastY - y));angleArr[num] = i;arcLenArr[num] = accArcLen;lastX = x;lastY = y;num++;}double arcPer = accArcLen / textLen;for (int i = 0; i < textLen; i++) {double arcL = i * arcPer + arcPer / 2.0;double ang = 0.0;for (int p = 0; p < arcLenArr.length - 1; p++) {if (arcLenArr[p] <= arcL && arcL <= arcLenArr[p + 1]) {ang = (arcL >= ((arcLenArr[p] + arcLenArr[p + 1]) / 2.0)) ? angleArr[p + 1] : angleArr[p];break;}}angR = (ang * Math.PI / 180f);Float x = radiusX * (float) Math.cos(angR) + radiusWidth;Float y = radiusY * (float) Math.sin(angR) + radiusHeight;double qxang = Math.atan2(radiusY * Math.cos(angR), -radiusX * Math.sin(angR));double fxang = qxang + Math.PI / 2.0;int subIndex = isTop ? i : textLen - 1 - i;String c = font.getText().substring(subIndex, subIndex + 1);//获取文字高宽FontMetrics fm = sun.font.FontDesignMetrics.getMetrics(f);int w = fm.stringWidth(c), h = fm.getHeight();if (isTop) {x += h * minRat * (float) Math.cos(fxang);y += h * minRat * (float) Math.sin(fxang);x += -w / 2f * (float) Math.cos(qxang);y += -w / 2f * (float) Math.sin(qxang);} else {x += (h * minRat) * (float) Math.cos(fxang);y += (h * minRat) * (float) Math.sin(fxang);x += w / 2f * (float) Math.cos(qxang);y += w / 2f * (float) Math.sin(qxang);}// 旋转AffineTransform affineTransform = new AffineTransform();affineTransform.scale(0.8, 1);if (isTop)affineTransform.rotate(Math.toRadians((fxang * 180.0 / Math.PI - 90)), 0, 0);elseaffineTransform.rotate(Math.toRadians((fxang * 180.0 / Math.PI + 180 - 90)), 0, 0);Font f2 = f.deriveFont(affineTransform);g2d.setFont(f2);g2d.drawString(c, x.intValue() + INIT_BEGIN, y.intValue() + INIT_BEGIN);}}/*** 画文字*/private static void drawFont(Graphics2D g2d, int circleWidth, int circleHeight, SealFont font) {if (font == null) {return;}//1.字体长度int textLen = font.getText().length();//2.字体大小,默认根据字体长度动态设定int size = font.getSize() == null ? (55 - textLen * 2) : font.getSize();//3.字体样式int style = font.getBold() ? Font.BOLD : Font.PLAIN;//4.构造字体Font f = new Font(font.getFamily(), style, size);g2d.setFont(f);FontRenderContext context = g2d.getFontRenderContext();String[] fontTexts = font.getText().split("\n");if (fontTexts.length > 1) {int y = 0;for (String fontText : fontTexts) {y += Math.abs(f.getStringBounds(fontText, context).getHeight());}//5.设置上边距float margin = INIT_BEGIN + (float) (circleHeight / 2 - y / 2);for (String fontText : fontTexts) {Rectangle2D rectangle2D = f.getStringBounds(fontText, context);g2d.drawString(fontText, (float) (circleWidth / 2 - rectangle2D.getCenterX()), margin);margin += Math.abs(rectangle2D.getHeight());}} else {Rectangle2D rectangle2D = f.getStringBounds(font.getText(), context);//5.设置上边距,默认在中心float margin = font.getMargin() == null ?(float) (circleHeight / 2 - rectangle2D.getCenterY()) :(float) (circleHeight / 2 - rectangle2D.getCenterY()) + (float) font.getMargin();g2d.drawString(font.getText(), (float) (circleWidth / 2 - rectangle2D.getCenterX()), margin);}}/*** 画圆*/private static void drawCircle(Graphics2D g2d, SealCircle circle, int x, int y) {if (circle == null) {return;}//1.圆线条粗细默认是圆直径的1/35int lineSize = circle.getLine() == null ? circle.getHeight() * 2 / (35) : circle.getLine();//2.画圆g2d.setStroke(new BasicStroke(lineSize));g2d.drawOval(x, y, circle.getWidth() * 2, circle.getHeight() * 2);}/*** 画私章*/public byte[] draw2(String imgFmt) throws Exception {if (mainFont == null || mainFont.getText().length() < 2 || mainFont.getText().length() > 4) {throw new IllegalArgumentException("请输入2-4个字");}int fixH = 18;int fixW = 2;//1.画布BufferedImage bi = new BufferedImage(size, size / 2, BufferedImage.TYPE_4BYTE_ABGR);//2.画笔Graphics2D g2d = bi.createGraphics();//2.1设置画笔颜色g2d.setPaint(Color.RED);//2.2抗锯齿设置g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);//3.写签名int marginW = fixW + borderSquare;float marginH;FontRenderContext context = g2d.getFontRenderContext();Rectangle2D rectangle;Font f;if (mainFont.getText().length() == 2) {if (stamp != null && stamp.trim().length() > 0) {bi = drawThreeFont(bi, g2d, mainFont.append(stamp), borderSquare, size, fixH, fixW, true);} else {f = new Font(mainFont.getFamily(), Font.BOLD, mainFont.getSize());g2d.setFont(f);rectangle = f.getStringBounds(mainFont.getText().substring(0, 1), context);marginH = (float) (Math.abs(rectangle.getCenterY()) * 2 + marginW) + fixH - 4;g2d.drawString(mainFont.getText().substring(0, 1), marginW, marginH);marginW += Math.abs(rectangle.getCenterX()) * 2 + (mainFont.getSpace() == null ? INIT_BEGIN : mainFont.getSpace());g2d.drawString(mainFont.getText().substring(1), marginW, marginH);//拉伸BufferedImage nbi = new BufferedImage(size, size, bi.getType());Graphics2D ng2d = nbi.createGraphics();ng2d.setPaint(Color.RED);ng2d.drawImage(bi, 0, 0, size, size, null);//画正方形ng2d.setStroke(new BasicStroke(borderSquare));ng2d.drawRect(0, 0, size, size);ng2d.dispose();bi = nbi;}} else if (mainFont.getText().length() == 3) {if (stamp != null && stamp.trim().length() > 0) {bi = drawFourFont(bi, mainFont.append(stamp), borderSquare, size, fixH, fixW);} else {bi = drawThreeFont(bi, g2d, mainFont, borderSquare, size, fixH, fixW, false);}} else {bi = drawFourFont(bi, mainFont, borderSquare, size, fixH, fixW);}g2d.dispose();ByteArrayOutputStream outputStream = new ByteArrayOutputStream();boolean png = ImageIO.write(bi,imgFmt, outputStream);byte[] imgBytes = outputStream.toByteArray();outputStream.flush();outputStream.close();return imgBytes;}/*** 画三字*/private static BufferedImage drawThreeFont(BufferedImage bi, Graphics2D g2d, SealFont font, int lineSize, int imageSize, int fixH, int fixW, boolean isWithYin) {fixH -= 9;int marginW = fixW + lineSize;//设置字体Font f = new Font(font.getFamily(), Font.BOLD, font.getSize());g2d.setFont(f);FontRenderContext context = g2d.getFontRenderContext();Rectangle2D rectangle = f.getStringBounds(font.getText().substring(0, 1), context);float marginH = (float) (Math.abs(rectangle.getCenterY()) * 2 + marginW) + fixH;int oldW = marginW;if (isWithYin) {g2d.drawString(font.getText().substring(2, 3), marginW, marginH);marginW += rectangle.getCenterX() * 2 + (font.getSpace() == null ? INIT_BEGIN : font.getSpace());} else {marginW += rectangle.getCenterX() * 2 + (font.getSpace() == null ? INIT_BEGIN : font.getSpace());g2d.drawString(font.getText().substring(0, 1), marginW, marginH);}//拉伸BufferedImage nbi = new BufferedImage(imageSize, imageSize, bi.getType());Graphics2D ng2d = nbi.createGraphics();ng2d.setPaint(Color.RED);ng2d.drawImage(bi, 0, 0, imageSize, imageSize, null);//画正方形ng2d.setStroke(new BasicStroke(lineSize));ng2d.drawRect(0, 0, imageSize, imageSize);ng2d.dispose();bi = nbi;g2d = bi.createGraphics();g2d.setPaint(Color.RED);g2d.setFont(f);g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);if (isWithYin) {g2d.drawString(font.getText().substring(0, 1), marginW, marginH += fixH);rectangle = f.getStringBounds(font.getText(), context);marginH += Math.abs(rectangle.getHeight());g2d.drawString(font.getText().substring(1), marginW, marginH);} else {g2d.drawString(font.getText().substring(1, 2), oldW, marginH += fixH);rectangle = f.getStringBounds(font.getText(), context);marginH += Math.abs(rectangle.getHeight());g2d.drawString(font.getText().substring(2, 3), oldW, marginH);}return bi;}/*** 画四字*/private static BufferedImage drawFourFont(BufferedImage bi, SealFont font, int lineSize, int imageSize, int fixH, int fixW) throws IOException, FontFormatException {int marginW = fixW + lineSize;//拉伸BufferedImage nbi = new BufferedImage(imageSize, imageSize, bi.getType());Graphics2D ng2d = nbi.createGraphics();ng2d.setPaint(Color.RED);ng2d.drawImage(bi, 0, 0, imageSize, imageSize, null);//画正方形ng2d.setStroke(new BasicStroke(lineSize));ng2d.drawRect(0, 0, imageSize, imageSize);ng2d.dispose();bi = nbi;Graphics2D g2d = bi.createGraphics();g2d.setPaint(Color.RED);g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);FontRenderContext context = g2d.getFontRenderContext();//Font f = new Font(font.getFamily(), Font.BOLD, font.getSize());//默认读取JDK 下的font字体File file = new File("config/font/simsun.ttf");System.out.println("已读取字体文件");Font f = Font.createFont(Font.TRUETYPE_FONT, file);f = f.deriveFont(Font.BOLD, font.getSize());g2d.setFont(f);Rectangle2D rectangle = f.getStringBounds(font.getText().substring(0, 1), context);float marginH = (float) (Math.abs(rectangle.getCenterY()) * 2 + marginW) + fixH;g2d.drawString(font.getText().substring(2, 3), marginW, marginH);int oldW = marginW;marginW += Math.abs(rectangle.getCenterX()) * 2 + (font.getSpace() == null ? INIT_BEGIN : font.getSpace());g2d.drawString(font.getText().substring(0, 1), marginW, marginH);marginH += Math.abs(rectangle.getHeight());g2d.drawString(font.getText().substring(3, 4), oldW, marginH);g2d.drawString(font.getText().substring(1, 2), marginW, marginH);return bi;}public Integer getSize() {return size;}public void setSize(Integer size) {this.size = size;}public Color getColor() {return color;}public void setColor(Color color) {this.color = color;}public SealFont getMainFont() {return mainFont;}public void setMainFont(SealFont mainFont) {this.mainFont = mainFont;}public SealFont getViceFont() {return viceFont;}public void setViceFont(SealFont viceFont) {this.viceFont = viceFont;}public SealFont getTitleFont() {return titleFont;}public void setTitleFont(SealFont titleFont) {this.titleFont = titleFont;}public SealFont getCenterFont() {return centerFont;}public void setCenterFont(SealFont centerFont) {this.centerFont = centerFont;}public SealCircle getBorderCircle() {return borderCircle;}public void setBorderCircle(SealCircle borderCircle) {this.borderCircle = borderCircle;}public SealCircle getBorderInnerCircle() {return borderInnerCircle;}public void setBorderInnerCircle(SealCircle borderInnerCircle) {this.borderInnerCircle = borderInnerCircle;}public SealCircle getInnerCircle() {return innerCircle;}public void setInnerCircle(SealCircle innerCircle) {this.innerCircle = innerCircle;}public Integer getBorderSquare() {return borderSquare;}public void setBorderSquare(Integer borderSquare) {this.borderSquare = borderSquare;}public String getStamp() {return stamp;}public void setStamp(String stamp) {this.stamp = stamp;}
}

SealCircle类:

package cn.com.yuanquanyun.bjca_scan;import lombok.Builder;
import lombok.Getter;
@Getter
@Builder
public class SealCircle {private Integer line;private Integer width;private Integer height;public Integer getLine() {return line;}public void setLine(Integer line) {this.line = line;}public Integer getWidth() {return width;}public void setWidth(Integer width) {this.width = width;}public Integer getHeight() {return height;}public void setHeight(Integer height) {this.height = height;}
}

SealFont类:

package cn.com.yuanquanyun.bjca_scan;import lombok.Builder;
import lombok.Getter;@Getter
@Builder
public class SealFont {private String text;private String family;private Integer size;private Boolean bold;private Double space;private Integer margin;public String getText() {return text;}public void setText(String text) {this.text = text;}public void setFamily(String family) {this.family = family;}public Integer getSize() {return size;}public void setSize(Integer size) {this.size = size;}public void setBold(Boolean bold) {this.bold = bold;}public Double getSpace() {return space;}public void setSpace(Double space) {this.space = space;}public Integer getMargin() {return margin;}public void setMargin(Integer margin) {this.margin = margin;}public String getFamily() {return family == null ? "宋体" : family;}public boolean getBold() {return bold == null ? true : bold;}public SealFont append(String text) {this.text += text;return this;}}

和印章生成相关的主要是以上这三个类。

测试类

public static void myTestCompanySeal() throws Exception {String mainText = "北京某某科技有限公司";String titleText = "合同专用章";String viceText = "0192834567";String keZhang = "公章刻章字体";//它会根据字体名称 去 jre下的font里去找这个字体。没有的话,会用默认字体。可以灵活控制Font的字体。上方的 Seal类中,采用的是读取本地的字体文件。而不是去jre 下的font里去找。两种方式都可以。String songTi = "宋体";//同上// 使用工具生成印章图片try {Seal.SealBuilder builder = Seal.builder();builder.size(432);builder.borderCircle(SealCircle.builder().line(10).width(210).height(210).build());if (mainText != null) {// 根据主文字长度,设置字体大小及边距int length = mainText.length();int size = 70;double space = 50;if (length > 0 && length <= 8) {space = 70;} else if (length == 9) {space = 60;} else if (length == 10) {space = 55;} else if (length == 11) {space = 50;} else if (length == 12) {space = 45;} else if (length == 13) {space = 40;} else if (length == 14) {space = 40;} else if (length == 15) {space = 37;} else if (length == 16) {size = 65;space = 35;} else if (length == 17) {size = 65;space = 35;} else if (length == 18) {size = 63;space = 33;} else if (length == 19) {size = 61;space = 31;} else if (length == 20) {size = 60;space = 30;} else if (length == 21) {size = 58;space = 29;} else if (length == 22) {size = 56;space = 28;} else if (length == 23) {size = 54;space = 27;} else if (length == 24) {size = 54;space = 27;} else if (length == 25) {size = 52;space = 26;} else {size = 60 - (length - 20) * 2;space = 30 - (length - 20) * 0.5;}builder.mainFont(SealFont.builder().text(mainText).family(keZhang).size(size).space(space).margin(10).build());}//builder.centerFont(SealFont.builder().family(songTi).text("★").size(140).build());//if (titleText != null) {builder.titleFont(SealFont.builder().family(keZhang).text(titleText).size(50).space(0.0).margin(100).build());}// 副文字 数字编号if (viceText != null) {builder.viceFont(SealFont.builder().family(songTi).text(viceText).size(30).space(20.0).margin(-10).build());}//Seal build = builder.build();byte[] draw = build.draw("png");FileUtil.writeBytes(draw, "C:\\Users\\Administrator\\Desktop\\seal.jpg");} catch (Exception e) {throw new CustomException("生成印章失败");}}
public static void main(String[] args) throws Exception {
//        myTestCompanySeal();//生成企业圆章// String legalName="王大拿";//三个字String legalName="王大拿印";//四个字String imgFmt = "png";String fontType = "宋体";makeLegalSeal(legalName,imgFmt,fontType);//生成个人私章}

效果:如下
请添加图片描述
测试私人印章类:

    private static byte[] makeLegalSeal(String legalName,String imgFmt,String fontType) throws Exception {// 加载刻章字体
//        String keZhang = "公章刻章字体";//这里的名字是字体名字,可以通过双击STXINGKA.ttf文件可以看到第一行的 字体名称: 公章刻章字体  华文行楷String keZhang = fontType;//这里的名字是字体名字,可以通过双击STXINGKA.ttf文件可以看到第一行的 字体名称: 公章刻章字体  华文行楷 "Lucida Bright"byte[] draw =Seal.builder().size(300).borderSquare(16).mainFont(SealFont.builder().text(legalName).family(keZhang).size(120).build()).build().draw(imgFmt);FileUtil.writeBytes(draw, "C:\\Users\\Administrator\\Desktop\\privateSeal.jpg");return draw;}

请添加图片描述
请添加图片描述

绘制方章

SquareSeal类:

package cn.com.yuanquanyun.utils.seal;import cn.hutool.core.io.IoUtil;
import lombok.Builder;
import lombok.Getter;import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.font.FontRenderContext;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;@Builder
@Getter
public class SquareSeal {// 起始位置private static final int INIT_BEGIN = 5;// 尺寸private Integer size;// 颜色private Color color;// 主字private SealFont mainFont;// 副字private SealFont viceFont;// 抬头private SealFont titleFont;// 中心字private SealFont centerFont;// 边线圆private SealCircle borderCircle;// 内边线圆private SealCircle borderInnerCircle;// 内线圆private SealCircle innerCircle;// 边线框private Integer borderSquare;// 加字private String stamp;/*** 画公章*/public byte[] draw() throws Exception {if (borderSquare != null) {return draw2(); // 画私章}//1.画布BufferedImage bi = new BufferedImage(size, size, BufferedImage.TYPE_4BYTE_ABGR);//2.画笔Graphics2D g2d = bi.createGraphics();//2.1抗锯齿设置//文本不抗锯齿,否则圆中心的文字会被拉长RenderingHints hints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);//其他图形抗锯齿hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);g2d.setRenderingHints(hints);//2.2设置背景透明度g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 0));//2.3填充矩形g2d.fillRect(0, 0, size, size);//2.4重设透明度,开始画图g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 1));//2.5设置画笔颜色g2d.setPaint(color == null ? Color.RED : color);//3.画边线圆if (borderCircle != null) {drawCircle(g2d, borderCircle, INIT_BEGIN, INIT_BEGIN);} else {throw new Exception("BorderCircle can not null!");}int borderCircleWidth = borderCircle.getWidth();int borderCircleHeight = borderCircle.getHeight();//4.画内边线圆if (borderInnerCircle != null) {int x = INIT_BEGIN + borderCircleWidth - borderInnerCircle.getWidth();int y = INIT_BEGIN + borderCircleHeight - borderInnerCircle.getHeight();drawCircle(g2d, borderInnerCircle, x, y);}//5.画内环线圆if (innerCircle != null) {int x = INIT_BEGIN + borderCircleWidth - innerCircle.getWidth();int y = INIT_BEGIN + borderCircleHeight - innerCircle.getHeight();drawCircle(g2d, innerCircle, x, y);}//6.画弧形主文字if (borderCircleHeight != borderCircleWidth) {drawArcFont4Oval(g2d, borderCircle, mainFont, true);} else {drawArcFont4Circle(g2d, borderCircleHeight, mainFont, true);}//7.画弧形副文字if (borderCircleHeight != borderCircleWidth) {drawArcFont4Oval(g2d, borderCircle, viceFont, false);} else {drawArcFont4Circle(g2d, borderCircleHeight, viceFont, false);}//8.画中心字drawFont(g2d, (borderCircleWidth + INIT_BEGIN) * 2, (borderCircleHeight + INIT_BEGIN) * 2, centerFont);//9.画抬头文字drawFont(g2d, (borderCircleWidth + INIT_BEGIN) * 2, (borderCircleHeight + INIT_BEGIN) * 2, titleFont);g2d.dispose();//ByteArrayOutputStream outputStream = new ByteArrayOutputStream();boolean png = ImageIO.write(bi, "PNG", outputStream);byte[] imgBytes = outputStream.toByteArray();outputStream.flush();outputStream.close();return imgBytes;}public void draw(String pngPath) throws Exception {byte[] imgBytes = draw();FileOutputStream fileOutputStream = new FileOutputStream(new File(pngPath));fileOutputStream.write(imgBytes);IoUtil.close(fileOutputStream);}/*** 绘制圆弧形文字*/private static void drawArcFont4Circle(Graphics2D g2d, int circleRadius, SealFont font, boolean isTop) {if (font == null) {return;}//1.字体长度int textLen = font.getText().length();//2.字体大小,默认根据字体长度动态设定int size = font.getSize() == null ? (55 - textLen * 2) : font.getSize();//3.字体样式int style = font.getBold() ? Font.BOLD : Font.PLAIN;//4.构造字体Font f = new Font(font.getFamily(), style, size);FontRenderContext context = g2d.getFontRenderContext();Rectangle2D rectangle = f.getStringBounds(font.getText(), context);//5.文字之间间距,默认动态调整double space;if (font.getSpace() != null) {space = font.getSpace();} else {if (textLen == 1) {space = 0;} else {space = rectangle.getWidth() / (textLen - 1) * 0.9;}}//6.距离外圈距离int margin = font.getMargin() == null ? INIT_BEGIN : font.getMargin();//7.写字double newRadius = circleRadius + rectangle.getY() - margin;double radianPerInterval = 2 * Math.asin(space / (2 * newRadius));double fix = 0.04;if (isTop) {fix = 0.18;}double firstAngle;if (!isTop) {if (textLen % 2 == 1) {firstAngle = Math.PI + Math.PI / 2 - (textLen - 1) * radianPerInterval / 2.0 - fix;} else {firstAngle = Math.PI + Math.PI / 2 - ((textLen / 2.0 - 0.5) * radianPerInterval) - fix;}} else {if (textLen % 2 == 1) {firstAngle = (textLen - 1) * radianPerInterval / 2.0 + Math.PI / 2 + fix;} else {firstAngle = (textLen / 2.0 - 0.5) * radianPerInterval + Math.PI / 2 + fix;}}for (int i = 0; i < textLen; i++) {double theta;double thetaX;double thetaY;if (!isTop) {theta = firstAngle + i * radianPerInterval;thetaX = newRadius * Math.sin(Math.PI / 2 - theta);thetaY = newRadius * Math.cos(theta - Math.PI / 2);} else {theta = firstAngle - i * radianPerInterval;thetaX = newRadius * Math.sin(Math.PI / 2 - theta);thetaY = newRadius * Math.cos(theta - Math.PI / 2);}AffineTransform transform;if (!isTop) {transform = AffineTransform.getRotateInstance(Math.PI + Math.PI / 2 - theta);} else {transform = AffineTransform.getRotateInstance(Math.PI / 2 - theta + Math.toRadians(8));}Font f2 = f.deriveFont(transform);g2d.setFont(f2);g2d.drawString(font.getText().substring(i, i + 1), (float) (circleRadius + thetaX + INIT_BEGIN), (float) (circleRadius - thetaY + INIT_BEGIN));}}/*** 绘制椭圆弧形文字*/private static void drawArcFont4Oval(Graphics2D g2d, SealCircle sealCircle, SealFont font, boolean isTop) {if (font == null) {return;}float radiusX = sealCircle.getWidth();float radiusY = sealCircle.getHeight();float radiusWidth = radiusX + sealCircle.getLine();float radiusHeight = radiusY + sealCircle.getLine();//1.字体长度int textLen = font.getText().length();//2.字体大小,默认根据字体长度动态设定int size = font.getSize() == null ? 25 + (10 - textLen) / 2 : font.getSize();//3.字体样式int style = font.getBold() ? Font.BOLD : Font.PLAIN;//4.构造字体Font f = new Font(font.getFamily(), style, size);//5.总的角跨度double totalArcAng = font.getSpace() * textLen;//6.从边线向中心的移动因子float minRat = 0.90f;double startAngle = isTop ? -90f - totalArcAng / 2f : 90f - totalArcAng / 2f;double step = 0.5;int alCount = (int) Math.ceil(totalArcAng / step) + 1;double[] angleArr = new double[alCount];double[] arcLenArr = new double[alCount];int num = 0;double accArcLen = 0.0;angleArr[num] = startAngle;arcLenArr[num] = accArcLen;num++;double angR = startAngle * Math.PI / 180.0;double lastX = radiusX * Math.cos(angR) + radiusWidth;double lastY = radiusY * Math.sin(angR) + radiusHeight;for (double i = startAngle + step; num < alCount; i += step) {angR = i * Math.PI / 180.0;double x = radiusX * Math.cos(angR) + radiusWidth, y = radiusY * Math.sin(angR) + radiusHeight;accArcLen += Math.sqrt((lastX - x) * (lastX - x) + (lastY - y) * (lastY - y));angleArr[num] = i;arcLenArr[num] = accArcLen;lastX = x;lastY = y;num++;}double arcPer = accArcLen / textLen;for (int i = 0; i < textLen; i++) {double arcL = i * arcPer + arcPer / 2.0;double ang = 0.0;for (int p = 0; p < arcLenArr.length - 1; p++) {if (arcLenArr[p] <= arcL && arcL <= arcLenArr[p + 1]) {ang = (arcL >= ((arcLenArr[p] + arcLenArr[p + 1]) / 2.0)) ? angleArr[p + 1] : angleArr[p];break;}}angR = (ang * Math.PI / 180f);Float x = radiusX * (float) Math.cos(angR) + radiusWidth;Float y = radiusY * (float) Math.sin(angR) + radiusHeight;double qxang = Math.atan2(radiusY * Math.cos(angR), -radiusX * Math.sin(angR));double fxang = qxang + Math.PI / 2.0;int subIndex = isTop ? i : textLen - 1 - i;String c = font.getText().substring(subIndex, subIndex + 1);//获取文字高宽FontMetrics fm = sun.font.FontDesignMetrics.getMetrics(f);int w = fm.stringWidth(c), h = fm.getHeight();if (isTop) {x += h * minRat * (float) Math.cos(fxang);y += h * minRat * (float) Math.sin(fxang);x += -w / 2f * (float) Math.cos(qxang);y += -w / 2f * (float) Math.sin(qxang);} else {x += (h * minRat) * (float) Math.cos(fxang);y += (h * minRat) * (float) Math.sin(fxang);x += w / 2f * (float) Math.cos(qxang);y += w / 2f * (float) Math.sin(qxang);}// 旋转AffineTransform affineTransform = new AffineTransform();affineTransform.scale(0.8, 1);if (isTop)affineTransform.rotate(Math.toRadians((fxang * 180.0 / Math.PI - 90)), 0, 0);elseaffineTransform.rotate(Math.toRadians((fxang * 180.0 / Math.PI + 180 - 90)), 0, 0);Font f2 = f.deriveFont(affineTransform);g2d.setFont(f2);g2d.drawString(c, x.intValue() + INIT_BEGIN, y.intValue() + INIT_BEGIN);}}/*** 画文字*/private static void drawFont(Graphics2D g2d, int circleWidth, int circleHeight, SealFont font) {if (font == null) {return;}//1.字体长度int textLen = font.getText().length();//2.字体大小,默认根据字体长度动态设定int size = 18;if (font.getSize() != null){size = font.getSize();}else {if (textLen > 13){size = 18 - (textLen - 13) < 12 ? 12 : 18 - (textLen - 13);}}//3.字体样式int style = font.getBold() ? Font.BOLD : Font.PLAIN;//4.构造字体Font f = new Font(font.getFamily(), style, size);g2d.setFont(f);FontRenderContext context = g2d.getFontRenderContext();String[] fontTexts = font.getText().split("\n");if (fontTexts.length > 1) {//当文字是多行时的处理方式int y = 0;for (String fontText : fontTexts) {y += Math.abs(f.getStringBounds(fontText, context).getHeight());}//5.设置上边距float margin = INIT_BEGIN*5 + (float) (circleHeight / 2 - y / 2);
//            System.out.println("1.margin==="+margin);for (String fontText : fontTexts) {Rectangle2D rectangle2D = f.getStringBounds(fontText, context);g2d.drawString(fontText, (float) (circleWidth / 2 - rectangle2D.getCenterX()), margin);margin += Math.abs(rectangle2D.getHeight());
//                System.out.println("2.margin==="+margin);}
//            System.out.println("3.margin==="+margin);} else {//当文字是单行时的处理方式Rectangle2D rectangle2D = f.getStringBounds(font.getText(), context);//5.设置上边距,默认在中心float margin = font.getMargin() == null ?(float) (circleHeight / 2 - rectangle2D.getCenterY()) :(float) (circleHeight / 2 - rectangle2D.getCenterY()) + (float) font.getMargin();g2d.drawString(font.getText(), (float) (circleWidth / 2 - rectangle2D.getCenterX()), margin);}}/*** 画圆*/private static void drawCircle(Graphics2D g2d, SealCircle circle, int x, int y) {if (circle == null) {return;}//1.圆线条粗细默认是圆直径的1/35int lineSize = circle.getLine() == null ? circle.getHeight() * 2 / (35) : circle.getLine();//2.画圆g2d.setStroke(new BasicStroke(lineSize));g2d.drawOval(x, y, circle.getWidth() * 2, circle.getHeight() * 2);}/*** 画矩形*/private static void drawRectangle(Graphics2D g2d, SealCircle circle, int x, int y) {if (circle == null) {return;}//1.圆线条粗细默认是圆直径的1/35int lineSize = circle.getLine() == null ? circle.getHeight() * 2 / (35) : circle.getLine();//2.画矩形g2d.setStroke(new BasicStroke(lineSize));g2d.drawRect(x, y, 289, circle.getHeight() * 1);}/*** 画私章*/public byte[] draw2() throws Exception {//1.画布BufferedImage bi = new BufferedImage(size, 106, BufferedImage.TYPE_4BYTE_ABGR);//2.画笔Graphics2D g2d = bi.createGraphics();//2.1抗锯齿设置//文本不抗锯齿,否则圆中心的文字会被拉长RenderingHints hints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);//其他图形抗锯齿hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);g2d.setRenderingHints(hints);//2.2设置背景透明度g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 0));//2.3填充矩形g2d.fillRect(0, 0, size, size);//2.4重设透明度,开始画图g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 1));//2.5设置画笔颜色g2d.setPaint(color == null ? Color.RED : color);//3.画边线圆if (borderCircle != null) {drawRectangle(g2d, borderCircle, INIT_BEGIN, INIT_BEGIN);} else {throw new Exception("BorderCircle can not null!");}//4.画上行文字drawFont(g2d, INIT_BEGIN * 60, INIT_BEGIN * 5, mainFont);//5.画横向文字drawFont(g2d, INIT_BEGIN * 60, INIT_BEGIN * 20, viceFont);//5.画下行文字drawFont(g2d, INIT_BEGIN * 60, INIT_BEGIN * 5, titleFont);g2d.dispose();ByteArrayOutputStream outputStream = new ByteArrayOutputStream();boolean png = ImageIO.write(bi, "PNG", outputStream);byte[] imgBytes = outputStream.toByteArray();outputStream.flush();outputStream.close();return imgBytes;}/*** 画三字*/private static BufferedImage drawThreeFont(BufferedImage bi, Graphics2D g2d, SealFont font, int lineSize, int imageSize, int fixH, int fixW, boolean isWithYin) {fixH -= 9;int marginW = fixW + lineSize;//设置字体Font f = new Font(font.getFamily(), Font.BOLD, font.getSize());g2d.setFont(f);FontRenderContext context = g2d.getFontRenderContext();Rectangle2D rectangle = f.getStringBounds(font.getText().substring(0, 1), context);float marginH = (float) (Math.abs(rectangle.getCenterY()) * 2 + marginW) + fixH;int oldW = marginW;if (isWithYin) {g2d.drawString(font.getText().substring(2, 3), marginW, marginH);marginW += rectangle.getCenterX() * 2 + (font.getSpace() == null ? INIT_BEGIN : font.getSpace());} else {marginW += rectangle.getCenterX() * 2 + (font.getSpace() == null ? INIT_BEGIN : font.getSpace());g2d.drawString(font.getText().substring(0, 1), marginW, marginH);}//拉伸BufferedImage nbi = new BufferedImage(imageSize, imageSize, bi.getType());Graphics2D ng2d = nbi.createGraphics();ng2d.setPaint(Color.RED);ng2d.drawImage(bi, 0, 0, imageSize, imageSize, null);//画正方形ng2d.setStroke(new BasicStroke(lineSize));ng2d.drawRect(0, 0, imageSize, imageSize);ng2d.dispose();bi = nbi;g2d = bi.createGraphics();g2d.setPaint(Color.RED);g2d.setFont(f);g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);if (isWithYin) {g2d.drawString(font.getText().substring(0, 1), marginW, marginH += fixH);rectangle = f.getStringBounds(font.getText(), context);marginH += Math.abs(rectangle.getHeight());g2d.drawString(font.getText().substring(1), marginW, marginH);} else {g2d.drawString(font.getText().substring(1, 2), oldW, marginH += fixH);rectangle = f.getStringBounds(font.getText(), context);marginH += Math.abs(rectangle.getHeight());g2d.drawString(font.getText().substring(2, 3), oldW, marginH);}return bi;}/*** 画四字*/private static BufferedImage drawFourFont(BufferedImage bi, SealFont font, int lineSize, int imageSize, int fixH, int fixW) {int marginW = fixW + lineSize;//拉伸BufferedImage nbi = new BufferedImage(imageSize, imageSize, bi.getType());Graphics2D ng2d = nbi.createGraphics();ng2d.setPaint(Color.RED);ng2d.drawImage(bi, 0, 0, imageSize, imageSize, null);//画正方形ng2d.setStroke(new BasicStroke(lineSize));ng2d.drawRect(0, 0, imageSize, imageSize);ng2d.dispose();bi = nbi;Graphics2D g2d = bi.createGraphics();g2d.setPaint(Color.RED);g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);FontRenderContext context = g2d.getFontRenderContext();Font f = new Font(font.getFamily(), Font.BOLD, font.getSize());g2d.setFont(f);Rectangle2D rectangle = f.getStringBounds(font.getText().substring(0, 1), context);float marginH = (float) (Math.abs(rectangle.getCenterY()) * 2 + marginW) + fixH;g2d.drawString(font.getText().substring(2, 3), marginW, marginH);int oldW = marginW;marginW += Math.abs(rectangle.getCenterX()) * 2 + (font.getSpace() == null ? INIT_BEGIN : font.getSpace());g2d.drawString(font.getText().substring(0, 1), marginW, marginH);marginH += Math.abs(rectangle.getHeight());g2d.drawString(font.getText().substring(3, 4), oldW, marginH);g2d.drawString(font.getText().substring(1, 2), marginW, marginH);return bi;}
}

测试类

/*** 创建方形企业章** @param companyName 企业名称:xxx企业* @param title       抬头:合同专用章* @param code        编号:1234567890123* @return* @throws Exception*/public static byte[] makeCompanySquareSeal (String companyName, String title, String code) throws Exception {byte[] img = null;if(companyName.length() <= 19){img = SquareSeal.builder().size(300).borderCircle(SealCircle.builder().line(4).width(95).height(95).build()).borderSquare(10).mainFont(SealFont.builder().text(companyName).space(12.0).margin(10).build()).viceFont(SealFont.builder().text(title).size(16).space(15.0).margin(0).build()).titleFont(SealFont.builder().text(code).size(12).space(9.0).margin(64).build()).color(Color.RED).build().draw();}else {//支持印章字体换行操作int len = companyName.length();companyName = companyName.substring(0,19)+"\n"+companyName.substring(19,len);img = SquareSeal.builder().size(300).borderCircle(SealCircle.builder().line(4).width(95).height(95).build()).borderSquare(10).mainFont(SealFont.builder().text(companyName).space(12.0).margin(10).build()).viceFont(SealFont.builder().text(title).size(16).space(15.0).margin(10).build())//margin 越大viceFont位置越往下,margin 为0时,位于中间位置.titleFont(SealFont.builder().text(code).size(12).space(9.0).margin(75).build()) //margin 越大titleFont位置越往下.color(Color.RED).build().draw();}return img;}public static void main(String[] args) throws Exception {byte[] bytes = makeCompanySquareSeal("中国某某某股份有限公司某某某某分公司", "招标专用章", "1234567890123");System.out.println("data:image/png;base64,"+ Base64.encode(bytes));}

在这里插入图片描述
主文字超过19个字,就换行。
在这里插入图片描述

相关文章:

Java中生成指定字体的印章

文章目录 1.引入字体2.Windows环境下3. Linux环境下 生成印章测试类绘制方章测试类 1.引入字体 2.Windows环境下 如果在Windows上安装JAVA环境时&#xff0c;没有安装单独的jre1.8.0_141的话。那么字体就只放到\jdk1.8.0_141\jre\lib\fonts目前下。 3. Linux环境下 cat /etc…...

Winodws核心编程 多线程

目录 一、基本概念 二、线程创建函数 三、Windows内核对象与句柄 四、简单的多线程案例 五、线程同步 - 互斥对象 六、多线程实现群聊的服务端和客户端 七、线程同步 - 事件对象 八、事件对象 与 互斥对象区别 九、线程同步 - 信号量 十、线程同步 - 关键代码段 十一…...

旺店通·企业版对接打通金蝶云星空查询调拨单接口与分布式调入单新增接口

旺店通企业版对接打通金蝶云星空查询调拨单接口与分布式调入单新增接口 源系统:旺店通企业版 旺店通是北京掌上先机网络科技有限公司旗下品牌&#xff0c;国内的零售云服务提供商&#xff0c;基于云计算SaaS服务模式&#xff0c;以体系化解决方案&#xff0c;助力零售企业数字化…...

关于对Java中volatile关键字的理解与简述

【版权声明】未经博主同意&#xff0c;谢绝转载&#xff01;&#xff08;请尊重原创&#xff0c;博主保留追究权&#xff09; https://blog.csdn.net/m0_69908381/article/details/134430096 出自【进步*于辰的博客】 启发之作&#xff1a;Java volatile关键字最全总结&#xf…...

37 _ 贪心算法:如何用贪心算法实现Huffman压缩编码?

基础的数据结构和算法我们基本上学完了,接下来几节,我会讲几种更加基本的算法。它们分别是贪心算法、分治算法、回溯算法、动态规划。更加确切地说,它们应该是算法思想,并不是具体的算法,常用来指导我们设计具体的算法和编码等。 贪心、分治、回溯、动态规划这4个算法思想…...

Unity中Shader矩阵的逆矩阵

文章目录 前言一、逆矩阵的表示二、逆矩阵的作用四、逆矩阵的计算五、顺序的重要性六、矩阵的逆总结1、求矩阵的逆前&#xff0c;这个矩阵必须得是个方阵2、只有 A x A ^-1^ A^-1^ x A 1时&#xff0c;A的逆才是A^-1^3、求2x2矩阵的逆&#xff1a;交换 a 和 b 的位置&#xf…...

我给网站做公安备案年度安全评估

我是卢松松&#xff0c;点点上面的头像&#xff0c;欢迎关注我哦&#xff01; 差不多从2020年开始&#xff0c;我们的网站每年11月左右就要去公安备案做一次年度的安全评估&#xff0c;而现在又新增了APP和小程序备案。如下图所示&#xff1a; 评估的内容也很简单&#xff0c…...

iceoryx(冰羚)-通信中间件解析

iceoryx(冰羚)-简介 iceoryx(冰羚)-Architecture iceoryx(冰羚)-Service Discovery iceoryx(冰羚)-examples-callbacks iceoryx(冰羚)-Listener设计 [iceoryx(冰羚)-ipc消息通信] [iceoryx(冰羚)-共享内存实现]...

Windows系统CMake+VS编译protobuf

目录 一些名词CMake构建VS工程下载protobuf源码下载CMake编译QT中使用 方案二失败&#xff1a;CMakeQT自带的Mingw编译参考链接 一些名词 lib dll lib库实际上分为两种&#xff0c;一种是静态链接lib库或者叫做静态lib库&#xff0c;另一种叫做动态链接库dll库的lib导入库或称…...

HarmonyOS开发(三):ArkTS基础

1、ArkTS演进 Mozilla创建了JS ---> Microsoft创建了TS ----> Huawei进一步推出ArkTS 从最初的基础逻辑交互&#xff08;JS&#xff09;,到具备类型系统的高效工程开发&#xff08;TS&#xff09;,再到融合声明式UI、多维状态管理等丰富的应用开发能力&…...

Java排序算法之堆排序

图解 堆排序是一种常见的排序算法&#xff0c;它借助了堆这种数据结构。堆是一种完全二叉树&#xff0c;它可以分为两种类型&#xff1a;最大堆和最小堆。在最大堆中&#xff0c;每个结点的值都大于等于它的子结点的值&#xff0c;而在最小堆中&#xff0c;每个结点的值都小于等…...

『GitHub项目圈选02』一款可实现视频自动翻译配音为其他语言的开源项目

&#x1f525;&#x1f525;&#x1f525;本周GitHub项目圈选****: 主要包含视频翻译、正则填字游戏、敏感词检测、聊天机器人框架、AI 换脸、分布式数据集成平台等热点项目。 1、pyvideotrans pyvideotrans 是一个视频翻译工具&#xff0c;可将一种语言的视频翻译为另一种语…...

Unity - Cinemachine

动态获取Cinemachine的内部组件 vCam.GetCinemachineComponent<T>() 动态修改Cinemachine的Transposer属性 var vCamComp transfrom.GetComponent<CinemachineVirtualCamera>(); var transposerComp vCamComp.GetCinemachineComponent<CinemachineTransposer&…...

准备搞OpenStack了,先装一台最新的Ubuntu 23.10

正文共&#xff1a;1113 字 25 图&#xff0c;预估阅读时间&#xff1a;2 分钟 依稀记得前面发了一篇Ubuntu的安装文档&#xff08;66%的经验丰富开发者和69%的学生更喜欢的Ubuntu的安装初体验&#xff09;&#xff0c;当时安装的是20.04.3的版本&#xff0c;现在看来已经是非常…...

Android 12 客制化修改初探-Launcher/Settings/Bootanimation

Android 12 使用 Material You 打造的全新系统界面&#xff0c;富有表现力、活力和个性。使用重新设计的微件、AppSearch、游戏模式和新的编解码器扩展您的应用。支持隐私信息中心和大致位置等新的保护功能。使用富媒体内容插入功能、更简便的模糊处理功能、经过改进的原生调试…...

【JavaEE初阶】 HTML基础详解

文章目录 &#x1f38b;什么是HTML&#xff1f;&#x1f340;HTML 结构&#x1f6a9;认识标签&#x1f6a9;HTML 文件基本结构&#x1f6a9;快速生成代码框架 &#x1f384;HTML 常见标签&#x1f6a9;注释标签&#x1f6a9;标题标签: h1-h6&#x1f6a9;段落标签: p&#x1f6…...

C# Socket通信从入门到精通(10)——如何检测两台电脑之间的网络是否通畅

前言: 我们在完成了socket通信程序开发以后,并且IP地址也设置好以后,可以先通过一些手段来测试两台电脑之间的网络是否通畅,如果确认了网络通畅以后,我们再测试我们编写的Socket程序。 1、同时按下键盘的windows键+"R"键,如下图: 下面两张图是两种键盘的情…...

python科研绘图:P-P图与Q-Q图

目录 什么是P-P图与Q-Q图 分位数 百分位数 Q-Q图步骤与原理 Shapiro-Wilk检验 绘制Q-Q图 绘制P-P图 什么是P-P图与Q-Q图 P-P图和Q-Q图都是用于检验样本的概率分布是否服从某种理论分布。 P-P图的原理是检验实际累积概率分布与理论累积概率分布是否吻合。若吻合&#xf…...

浅尝:iOS的CoreGraphics和Flutter的Canvas

iOS的CoreGraphic 基本就是创建一个自定义的UIView&#xff0c;然后重写drawRect方法&#xff0c;在此方法里使用UIGraphicsGetCurrentContext()来绘制目标图形和样式 #import <UIKit/UIKit.h>interface MyGraphicView : UIView endimplementation MyGraphicView// Onl…...

网络安全黑客技术自学

前言 一、什么是网络安全 网络安全可以基于攻击和防御视角来分类&#xff0c;我们经常听到的 “红队”、“渗透测试” 等就是研究攻击技术&#xff0c;而“蓝队”、“安全运营”、“安全运维”则研究防御技术。 无论网络、Web、移动、桌面、云等哪个领域&#xff0c;都有攻与防…...

【文件读取/包含】任意文件读取漏洞 afr_3

1.1漏洞描述 漏洞名称任意文件读取漏洞 afr_3漏洞类型文件读取/包含漏洞等级⭐⭐⭐⭐⭐漏洞环境docker攻击方式 1.2漏洞等级 高危 1.3影响版本 暂无 1.4漏洞复现 1.4.1.基础环境 靶场docker工具BurpSuite 1.4.2.环境搭建 1.创建docker-compose.yml文件 version: 3.2 servi…...

第四章:单例模式与final

系列文章目录 文章目录 系列文章目录前言一、单例模式二、final 关键字总结 前言 单例模式与final关键字。 一、单例模式 设计模式是在大量的实践中总结和理论化之后优选的代码结构、编程风格、以及解决问题的思考方式。就像是经典的棋谱&#xff0c;不同的棋局&#xff0c;我…...

深入Android S(12.0) 探索 Android Framework 之 SystemServer 进程启动详解

深入学习 Android Framework 第三&#xff1a;深入Android S(12.0) 探索 Android Framework 之 SystemServer 进程启动详解 文章目录 深入学习 Android Framework前言一、Android 系统的启动流程1. 流程图2. 启动流程概述 二、源码详解1. 时序图2. 源代码1、ZygoteInit # main…...

搜维尔科技:【软件篇】TechViz是一款专为工程设计的专业级3D可视化软件

在沉浸式房间内深入研究您自己的 3D 数据 沉浸式房间是一个交互式虚拟现实空间&#xff0c;其中每个表面&#xff08;墙壁、地板和天花板&#xff09;都充当投影屏幕&#xff0c;创造高度沉浸式的体验。这就像您的 3D 模型有一个窗口&#xff0c;您可以在其中从不同角度走动、…...

android Handler

一、Handler的作用 1、Handler的作用是在andorid中实现线程间的通信。我们常说的说的&#xff0c;子线程处理逻辑&#xff0c;主线程更新UI是上述情况的一个子集。 二、源码分析 1、Handler源码 源码地址&#xff1a;http://androidxref.com/7.1.1_r6/xref/frameworks/base/co…...

【Ubuntu·系统·的Linux环境变量配置方法最全】

文章目录 概要读取环境变量的方法小技巧 概要 在Linux环境中&#xff0c;配置环境变量是一种常见的操作&#xff0c;用于指定系统或用户环境中可执行程序的搜索路径。 读取环境变量的方法 在Linux中&#xff0c;可以使用以下两个命令来读取环境变量&#xff1a; export 命令…...

Django之模板层

【1】模板之变量 在Django模板中要想使用变量关键是使用点语法。 获取值的语法是&#xff1a;{{ 变量名 }} Python中所有的数据类型包括函数&#xff0c;类等都可以调用 【2】模板之过滤器 过滤器语法 {{ obj | filter_name&#xff1a;param }} obj&#xff1a;变量名字&…...

社区论坛小程序系统源码+自定义设置+活动奖励 自带流量主 带完整的搭建教程

大家好啊&#xff0c;又到了罗峰来给大家分享好用的源码的时间了。今天罗峰要给大家分享的是一款社区论坛小程序系统。社区论坛已经成为人们交流、学习、分享的重要平台。然而&#xff0c;传统的社区论坛往往功能单一、缺乏个性化设置&#xff0c;无法满足用户多样化的需求。而…...

2023亚太杯数学建模C题思路解析

文章目录 0 赛题思路1 竞赛信息2 竞赛时间3 建模常见问题类型3.1 分类问题3.2 优化问题3.3 预测问题3.4 评价问题 4 建模资料5 最后 0 赛题思路 &#xff08;赛题出来以后第一时间在CSDN分享&#xff09; https://blog.csdn.net/dc_sinor?typeblog 1 竞赛信息 2023年第十三…...

acme在同一台服务器上设置多个Ali_key实现自动ssl申请和续期

在同一台服务器上设置多个Ali_key&#xff0c;您可以按照以下步骤进行操作&#xff1a; 首先&#xff0c;确保您已经安装了acme.sh工具。如果没有安装&#xff0c;请先安装acme.sh&#xff0c;您可以使用以下命令安装acme.sh&#xff1a; curl https://get.acme.sh | sh安装完…...