docker-alpine
docker-alpine copied to clipboard
java.awt.geom.Rectangle2D do not work
Hi, when i use the images to write a string in picture,the method can run and no errors , but can not write string to picture , the code like this
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.font.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.FileInputStream;
public class AppsData {
public static void main(String[] args) throws IOException,FontFormatException,InterruptedException {
Font font=Font.createFont(Font.TRUETYPE_FONT,new File(args[0]));
int with=300;
int hight=300;
BufferedImage image=new BufferedImage(with,hight,BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d=image.createGraphics();
image=g2d.getDeviceConfiguration().createCompatibleImage(with,hight,3);
g2d.dispose();
g2d=image.createGraphics();
g2d.setColor(new Color(10));
g2d.setStroke(new BasicStroke(1.0F));
FontRenderContext context=g2d.getFontRenderContext();
Rectangle2D bounds=font.getStringBounds(“中文”,context);
double x=(with-bounds.getWidth())/2.0;
double y=(hight-bounds.getHeight())/2.0;
double ascent=-bounds.getCenterY();
double baseY=y+ascent;
g2d.rotate(Math.toRadians(-45.0D),with/2,hight/2);
g2d.drawString(args[0],(int)x,(int)baseY);
g2d.dispose();
ImageIO.write(image,"png",new File(args[1]));
}
}
the resoult is like

but when i add the font file in ${JRE_HOME}/lib/fonts/fallback/ , then use Font font =new Font("宋体",1,24); it works
i want this

when i do not in docker all of the method is work ~
ENV:
alpine docker version 3.7glibc 1.2JDK: oracle jdk1.8_65
please give some suggest to solve this problem ~
thinks ~