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 / GUI / May 2004

Tip: Looking for answers? Try searching our database.

getScaledInstance for BufferedImage.

Thread view: 
Roedy Green - 13 May 2004 07:56 GMT
getScaledInstance produces an Image out of my BufferedImage.
It does not produced a BufferedImage I can simply cast.

What is the best to way to either convert it back to a BufferedImage
or to get myself a scaled BufferedImage?

Signature

Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Roedy Green - 13 May 2004 08:22 GMT
>getScaledInstance produces an Image out of my BufferedImage.
>It does not produced a BufferedImage I can simply cast.
>
>What is the best to way to either convert it back to a BufferedImage
>or to get myself a scaled BufferedImage?

After some horsing around here is what appears to work, but my choice
of type  TYPE_INT_BGR was arbitrary.  It seems goofy to change from
JPEG to bit map to convert back to JPEG map gain.

// magnify which has side effect of turning back to plain Image.
Image magnifiedImage
 = image.getScaledInstance( magnifiedImageWidth,
                                         magnifiedImageHeight,
                                         BufferedImage.SCALE_SMOOTH);

// convert back to BufferedImage
BufferedImage bufferedImage = new BufferedImage (

magnifiedImageWidth,

magnifiedImageHeight,

BufferedImage.TYPE_INT_BGR);
bufferedImage.createGraphics().drawImage(
                       magnifiedImage, 0, 0, this /* observer */ );

// write out the BufferedImage as a JPEG
ImageIO.write( bufferedImage,
                       "JPEG" /* format desired */ ,
                        file );

.

Signature

Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Knute Johnson - 13 May 2004 18:53 GMT
>>getScaledInstance produces an Image out of my BufferedImage.
>>It does not produced a BufferedImage I can simply cast.
[quoted text clipped - 29 lines]
>
> .

Roedy:

You can scale it with an AffineTransform.

Signature

Knute Johnson
email s/nospam/knute/
Molon labe...



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.