Hello,
I am trying to create and Image and diplay it on an HTML page
without ever writing it to disk.
This code currently giveas a broken image link :-( Although if I
output to a file the image displays fine ????)
/*************** Image Code **************/
package prototype;
import javax.swing.ImageIcon;
import java.awt.image.BufferedImage;
import java.awt.Image;
import java.awt.Graphics2D;
import java.io.*;
import java.awt.Color;
import java.awt.Font;
import java.awt.RenderingHints;
public class TestGif{
private int LEFT_ALIGN = 12;
private String BASE_IMAGE = "x.gif";
public String getImage(){
String count = "0";
Image img = new ImageIcon(BASE_IMAGE).getImage();
BufferedImage bi = new BufferedImage( img.getWidth(null),
img.getHeight(null),
BufferedImage.TYPE_INT_RGB);
Graphics2D big = bi.createGraphics();
big.drawImage(img, 0, 0, null);
// big.setColor(Color.black);
// big.setFont(new Font("Arial",Font.BOLD,11));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try{
Acme.JPM.Encoders.GifEncoder encoder = new
Acme.JPM.Encoders.GifEncoder(bi,bos);
encoder.encode();
bos.close();
}catch(IOException e){ e.printStackTrace(); }
return new String(bos.toByteArray());
}
}
/******************** End Image Code ********************************/
/******************* Servlet Code ************************************/
import prototype.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import javax.swing.text.*;
import java.io.*;
import java.io.IOException;
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import javax.servlet.*;
import javax.servlet.http.*;
public class Test extends HttpServlet
{
public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
TestGif gifBean = new TestGif();
response.setContentType("image/gif");
PrintWriter out = response.getWriter();
out.print(gifBean.getImage());
out.close();
}
}
/******************* End Servlet Code ********************************/
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".