The following code does write to a premade image. The resulting image, though, has significant problems.

- the original png file is a 3D button with Index Transparency and a matte so that the gif file would blend in with the page background color

the resulting gif file is flat, the matte is gone, and the text doesnít look smooth. The resulting file is therefore is not something you would get from Adobe Photoshop or Fireworks and doesnít look professional.

If anyone has suggestions, Iím all ears. Is it impossible to get a high quality 3D button using Java?


package jservlets;

import java.util.*;
import java.sql.*;

import javax.servlet.*;
import javax.servlet.http.*;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;

public class CreateRectangleTest extends HttpServlet
PrintWriter out;
PrintWriter err;

private void CreateButton(HttpServletRequest request, HttpServletResponse response) throws IOException
out.println ("\n\n+++++ CreateButton Process +++++\n");

String pathToWeb = getServletContext().getRealPath(File.separator);

File f = new File(pathToWeb + "activities.png");

BufferedImage bufferedImage =;

// 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.drawString("Activities", 40, 40);

// Disposes of this graphics context and releases any system resources that it is using.

// Save as gif
File file = new File("myactivities.gif");
ImageIO.write(bufferedImage, "gif", file);


catch (IOException sqlio)

out.println("IOException: Could not execute Create Button.");
err.println (sqlio.getMessage () ) ;


public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException


out = response.getWriter();
err = response.getWriter();

CreateButton(request, response);



catch (IOException io)
err.println (io.getMessage () ) ;

catch(Throwable io)


public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
doPost(request, response);