Hi,

if you want to apply jpegs the following code should code should give you the image as 
a BufferedImage from a file
with name filename (using Java 1.2):

   try
   {
     FileInputStream inStream = new FileInputStream (filename);
     JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(inStream);

     theImage = decoder.decodeAsBufferedImage();
     inStream.close();
   }
   catch (Exception ex)
   {
     theImage = null;
     ex.printStackTrace();
   }

Probably for patent reasons, there seems to be no easy accessible GIFCodec which could 
do the same for gif-
encoded Images

Therefore I decided to switch to the png-Format for the image and applied successfully 
the png decoder described in
the O'Reilly book "Java 2D Graphics" by Jonathan Knudsen (there is no CD in it, and 
the code seems not be on the
web, so I had to do the copying work manually but it worked).

Rupert







> William Crawford wrote:
>
> [..]
> > Essentially, you need to create an AWT context before using AWT calls. In a
> > servlet you need to do this explicitly, while in an Applet or Application
> > the context is pre-existing. That's why most of the sample code you see in
> > books won't run when dropped into a servlet.
> >
> > I haven't done this in a while, but if you create a new java.awt.Frame
> > object, call addNotify(), you should then be able to call
> > getToolkit().getImage("my.gif") on the Frame without any problems.
> >
>
> Actually, something a bit simpler could do the trick, like:
>
> Component dummyComponent = new Canvas();
>
> and then straight ahead into:
>
>             Image image = dummyComponent.getImage(filename);
> or
>             Image image = dummyComponent.createImage(
>                 new MemoryImageSource(width,height, pixels, 0,width) );
>
> But if you are on Linux, see another message by Chris, because importing
> java.awt.* won't mean that you DO have a native peer. Relying on the
> existance of native peers is quite a headache at times.
>
> Kostas
>
> > At 06:59 AM 6/22/2000 -0700, Jim Graham wrote:
> > >Hi,
> > >I've been trying to get an image into my servlet,
> > >but when I try it dies when it hits the call below:
> > >
> > >Image myImage =
> > >Toolkit.getDefaultToolkit().getImage("my.gif");
> > >
> > >
> > >Any ideas on how to get an image into a servlet?
> > >Thanks,
> > >Jim
> > >
> > >
> > >
> > >__________________________________________________
> > >Do You Yahoo!?
> > >Send instant messages with Yahoo! Messenger.
> > >http://im.yahoo.com/
> > >
> > >___________________________________________________________________________
> > >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
> >
> > ---
> > William Crawford                                        + 01 617 577 7844
> > Invantage, Inc                                            [EMAIL PROTECTED]
>
> ___________________________________________________________________________
> 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

Reply via email to