If u'r image is in gif/jpeg format, simply write it to out as follows
:
out.write(bytes,0,bytes.length())
U might have to indicate before hand to "out" that it should expect
a "image/jpeg" or "image/gif" by setting the content type (res.setContentType("image/jpeg")).
(Warning : If it is multi-media content, use content-type of multi-part/x-www-url-encoded
(I could be somewhat off here). There's a bit more to it, like boundary
blah-blah, but that's another story.)
If it is in unknown format, do the following steps:
a) create an Image (say, image) object using Toolkit.getDefaultToolkit.createImage(bytes);
(not a ClassLoader,
oops)
b) instantiate an ImageObserver, and its peer
Frame f = new Frame();
f.addNotify();
c) Instantiate a MediaTracker and load the image
MediaTracker mt = new MediaTracker(f);
mt.add(image,0);
try{
mt.waitForAll();
}catch(....){ raiseHell();
makeNoise();}
d) Create an image in the frame and
draw the image on it
int height = image.getHeight(frame);
int width = image.getWidth(frame);
Image offscreen = frame.createImage(width,
height);
Graphics g = offscreen.getGraphics();
// and now the key thing.
All this blah-blah for this one line
g.drawImage(image,0,0,frame);
e) So far so good. But, how do u write it to the
outputsteam
Well try out GifEncoder
from www.acme.com/java
GifEncoder gif = new GifEncoder(offscreen,
out);
// Hang on. It's not yet
done.
gif.encode();
// THAT does it.
At the end of it all, if it doesn't work, kindly forget about this balderdash.
If it does, please "notify()", I am "wait()"ing.
- Uddipan.
Nilesh Khedkar wrote:
Thanks Uddipan,Actually, I am getting Byte Array, but somehow I am not able to use
Classloader to create Image object. Can you please explain me the method in
some detail?Thanks in Advance
Nilesh
>From: Uddipan Bagchi <[EMAIL PROTECTED]>
>Reply-To: Uddipan Bagchi <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: Re: Images
>Date: Tue, 12 Oct 1999 14:46:44 +0530
>
>I suppose you have retrieved a ResultSet object (say, rs), and also know
>that which column number (say, i) the image is stored in.
>
>If I recall correctly, you may use rs.getBinaryStream(i) to retrieve the
>image as an InputStream. You can then process it with any of the
>InputStream wrappers to get at the bytes associated with image. (Please
>note that this approach works fine for large binary objects - for the
>others, just use rs.getBytes(i) to get an array of bytes).
>
>Use this byte array to create an Image object (thru a ClassLoader, etc).
>
>This image object may then be encoded into a gif or jpeg using various
>JPEG and GIF encoders (refer www.acme.com for some).
>
>Hope it helps.
>
>- Uddipan.
>
>===========================================================================
>To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
>JSP-INTEREST".
>FAQs on JSP can be found at:
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
