Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2007

Tip: Looking for answers? Try searching our database.

Rescaling image file while printing

Thread view: 
Elliot - 14 Nov 2007 17:37 GMT
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/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.