http://www.robinswebsitestudio.com/ButtonSamples/buttons.html

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?

Robin
*********************************************************

package jservlets;

import java.io.*;
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
{
try
{
out.println ("\n\n+++++ CreateButton Process +++++\n");
out.println("<P>");

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);


}

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
{

try
{
response.setContentType("text/html");

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

CreateButton(request, response);

out.println("</body></html>");
out.close();


}

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

catch(Throwable io)
{
io.printStackTrace();
}



}

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

}