0

可以在新图片中看到 pdf.png,但在新图片中看不到字符串“Hello”

public void generateImage() throws Exception{
        int width = 220;
        int height = 50;
        BufferedImage image = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
        Graphics g = image.getGraphics();
        g.setColor(new Color(255,255,255));
        g.fillRect(0, 0, width, height);
        Font font = new Font("宋体",Font.BOLD,10);
        g.setFont(font);
        BufferedImage image2 = ImageIO.read(new File("data/icon/pdf.png"));
        g.drawImage(image2, 0, 0, 44, 42, null);
        g.drawString("Hello", 50, 5);
        g.dispose();
        File f = new File("data/icon/"+fileName+".png");
        FileOutputStream fos = new FileOutputStream(f);
        ImageIO.write(image,"PNG",fos);
        fos.close();
}
4

2 回答 2

2

It looks like you are setting the color to white and never setting any other color. The result is extremely low contrast.

于 2012-03-09T07:09:55.263 回答
2
g.drawString("Hello", 50, 5);

在这一行上操作坐标值,即 50 和 5,并测试文本“Hello”是否出现。

于 2012-03-09T07:02:24.167 回答