Rescaling image file while printing

E

Elliot

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
 
K

Knute Johnson

Elliot said:
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

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?
 
K

Knute Johnson

Elliot said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top