gliderlabs / gliderlabs/docker-alpine

java.awt.geom.Rectangle2D do not work

Open
#393 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Shell
Stars
5.7k
Forks
530
PR merge metrics
No merged PRs in 30d

Description

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
```java
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

![image](https://user-images.githubusercontent.com/7694194/37565878-47d79f90-2aec-11e8-9e1b-48c4678aada7.png)

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
![image](https://user-images.githubusercontent.com/7694194/37565889-67204b68-2aec-11e8-96a6-3385b9967913.png)

when i do not in docker all of the method is work ~

`ENV:`
- `alpine docker version 3.7`
- `glibc 1.2`
- `JDK: oracle jdk1.8_65`

please give some suggest to solve this problem ~

thinks ~

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.