[2427] in java-interest

home help back first fref pref prev next nref lref last post

Re: g.drawImage() -- Why doesn't it work??

daemon@ATHENA.MIT.EDU (Jim Graham)
Sun Oct 1 21:44:50 1995

Date: Sun, 1 Oct 1995 17:04:22 -0700
From: flar@bendenweyr.Eng.Sun.COM (Jim Graham)
To: java-interest@java.Eng.Sun.COM, mikea@ai.mit.edu

Hi Mike,

First, I'd like to point anyone who might be having trouble with images
in the JDK at the beta Image API conversion guide online:

	http://java.sun.com/JDK-prebeta1/converting/images.html

>     Hi.  I am in the process of creating an applet with a GUI.  I have
> "painted" a nice background with some other stuff on it (3Drectangles,
> etc.)  I would also like to add a GIF to my GUI, and have loaded one
> up with a getImage command that seems to be working well.  However,
> when I use g.drawImage in paint(), I get no complier error, no runtime
> error, but no results.  Any ideas why???

In the Beta APIs the drawImage method will always return immediately
even if none of the data is loaded.  The ImageObserver object that
you passed in as the final parameter will be notified as the image
is loaded.  You can use your Applet as the ImageObserver since, by
default, it implements the ImageObserver interface and executes repaint()
when more data comes in for the image.

If you are doing that and you still get no output, then the image
probably had an error and the imageUpdate method in your Applet was
notified, but we currently don't do anything with image errors in
the default imageUpdate method - you would have to override it and
look for errors yourself.  I have that problem on my list to address.

> I even tried stripping away
> the rest of the background and JUST drawing the picture...to no avail.
>   Furthermore, asuming I ever get this to display, is it possible to
> "crop" the image (set its demensions) through java, or is that
> something that I'd have to do through a GIF editing program?

There is a built-in filter to do cropping in Beta.  Check out the
java.awt.image.CropImageFilter class for an example.  Alternately you
could just draw the image with a clip rectangle and only those parts
that show through the clip rectangle will be rendered.  If the image
is very large and you only want to show a small part of it, then using
a cropping filter will allow us to conserve space internally by only
dithering the part that will be shown.

				...jim
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post