Hi All,
I need to rescale and print some jpeg and bmp files in Java
application. My code is inside of a class "GraphicPages" that
implements Printable.
The actual rescale logic is contained in the print() method and uses
the following line to locate and initialize the Image itself
Image imgSource ;
this.imgSource =
Toolkit.getDefaultToolkit().getImage(shp.getPath());
To implement the rescale logic I need to use imgSource.getWidth and
Height. If I use my printable class as the observer
"imgSource.getWidth(this)" I get an error saying:
"getWidth(java.awt.image.ImageObserver) in java.awt.Image cannot be
applied to (GraphicPages)
The only way I can get this to compile is to use "null" instead of
"this" for the ImageObserver parameter.
If I use "null" will this work?
Thanks
Elliot
Knute Johnson - 14 Nov 2007 18:32 GMT
> Hi All,
>
[quoted text clipped - 23 lines]
>
> Elliot
The error implies that GraphicPages is not an ImageObserver. Unless you
are trying to get this to run on a 20th century runtime, why don't you
load your image with some other method?

Signature
Knute Johnson
email s/nospam/knute/
Elliot - 14 Nov 2007 19:57 GMT
Knute
I'm using this in order to use getWidth()
Thx
Elliot
Knute Johnson - 14 Nov 2007 20:44 GMT
> Knute
>
> I'm using this in order to use getWidth()
>
> Thx
> Elliot
Elliot:
Look at the BufferedImage and ImageIO classes. The BufferedImage is an
improvement over the original Image and can be read and written with the
ImageIO class methods.
To see examples of all methods of loading images goto my webpage
http://www.knutejohnson.com and look at the image loading examples. The
source code is there too.

Signature
Knute Johnson
email s/nospam/knute/