0

it is can by see pdf.png in the new Picture, but can't see the String "Hello" in the new Picture

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();
}
kleopatra
  • 51,061
  • 28
  • 99
  • 211
xxddwdj
  • 31
  • 1
  • 4

2 Answers2

2
g.drawString("Hello", 50, 5);

On this line manipulate the coordinate values, i.e. 50 and 5, and test whether the text "Hello" appears.

Juvanis
  • 25,802
  • 5
  • 69
  • 87
2

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

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • g.drawImage(image2, 0, 0, 80, 80, null); g.setColor(Color.red); g.drawString("Hello", 50, 5); – xxddwdj Mar 09 '12 at 07:27
  • Did that help? Try `g.drawString("Hello", 50, 12)`. See also this [example](http://stackoverflow.com/a/2658663/230513). – trashgod Mar 09 '12 at 11:41