T write the image to the HTML page you can use an output stream. Try
something like:
ServletOutputStream out = res.getOutputStream();
<...>
res.setContentType("image/jpeg");
out.write(result.getBytes("I_IMAGE"));
This uses the image data from a database but iot works the sae,. It is a
byte array at this point. If you want to use a JPEGEncoder sun has one in
com.sun.image.codec.jpeg.JPEGImageEncoder
-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Ross
Wayland
Sent: Wednesday, November 17, 1999 6:09 AM
To: [EMAIL PROTECTED]
Subject: jpeg images and servlets
Hi,
I'm having a problem displaying jpeg images via a servlet...
Context:
The jpeg images are being passed from another java application
in the form of a byte[]. The function of the servlet is to grab
the byte[] and display it on a dynamically created html page.
I initially tried using the jpeg encoder from www.acme.com. Their GIF
encoder works great but I was unable to get their JPEG encoder to work
so I turned to the jpeg encoder built into JDK 1.2 which seems to require
transforming Image to BufferedImage.
The code snippet below produces an image on the html page with the correct
dimensions, but the image is solid black. Can anyone provide some pointers
as to where I went astray or suggest a better way of handling the
transformation from byte[] to BufferedImage? thanks in advance.
Ross
.
.
.
//dataStream is a byte[] with the image data
response.setContentType("image/jpeg");
ServletOutputStream out = response.getOutputStream();
BufferedImage bi = draw(dataStream);
encode(bi,out);
.
.
.
public static BufferedImage draw(byte[] dataStream) {
BufferedImage bi =
new BufferedImage(WIDTH,HEIGHT,BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = bi.createGraphics();
Image image = Toolkit.getDefaultToolkit().createImage(dataStream);
g2d.drawImage(image,null,null);
g2d.dispose();
return(bi);
}//end draw
public static void encode(BufferedImage bi, OutputStream out)
throws IOException {
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
param.setQuality(1.0f,false);
encoder.encode(bi,param);
}//end encode
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html