http://www.robinswebsitestudio.com/ButtonSamples/buttons.html
以下代码确实写入了预制图像。但是,生成的图像存在重大问题。
原始 png 文件是具有索引透明度和遮罩的 3D 按钮,以便 gif 文件与页面背景颜色融合
生成的 gif 文件是扁平的,遮罩消失了,文本看起来也不平滑。因此,生成的文件不是您从 Adobe Photoshop 或 Fireworks 获得的文件,而且看起来也不专业。
如果有人有建议,我会全力以赴。使用 Java 就不可能获得高质量的 3D 按钮吗?
String pathToWeb = getServletContext().getRealPath(File.separator);
File f = new File(pathToWeb + "activities.png");
BufferedImage bufferedImage = ImageIO.read(f);
// Create a graphics which can be used to draw into the buffered image
Graphics2D g2d = bufferedImage.createGraphics();
g2d.setFont(new Font( "Arial", Font.BOLD, 15 ));
//create a string with black
g2d.setColor(Color.black);
g2d.drawString("Activities", 40, 40);
// Disposes of this graphics context and releases any system resources that it is using.
g2d.dispose();
// Save as gif
File file = new File("myactivities.gif");
ImageIO.write(bufferedImage, "gif", file);