对java图形编程不熟悉,这个问题不知道如何解决,问题如下
我打算生成一张图片,该图片包括一张原先的图片和字符串,结果生成的图片包含原先图片,但是看不到drawString方法中字符串内容
生成图片方法代码如下:
[code="java"]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();
}[/code]