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 / July 2006

Tip: Looking for answers? Try searching our database.

Image scaling by Width & Height constant - preserve aspect ratio

Thread view: 
Farce Milverk - 17 Jul 2006 18:18 GMT
Hi,

I'm looking for an algorithm to resize an image of arbitrary size to a
"fixed" / required width and height.

For example, my application requires that images be no larger than 440 pixel
(height) x 780 (wide)

So the "preferred size" would be 440 x 780

If an image is too large, either by width or height it should be resized
until less than or equal to 440 x 780 and preserve aspect ratio.

Thanks for any tips.

Farce
Sigmund Hansen - 18 Jul 2006 00:36 GMT
> Hi,
>
[quoted text clipped - 12 lines]
>
> Farce

Ok,
if the ratio is lower than 780/440 (your fixed width split on the fixed
height), then you need to resize by height, if it is (equal to
or(equality can be put in either one of the two methods)) higher than
this one, then it should be resized by width...
So:

double fixedRatio = 780.0/440.0;
if((double)image.getWidth()/image.getHeight >= fixedRatio)
{
    resizeImage( image, 780, image.getHeight()/(image.getWidth()/780.0) );
// This requires that there exists a resizeImage method, but I don't
know what you want, drawImage or if you are making a file or what, so
this is kind of pseudo-code.
}
else
{
    resizeImage( image, image.getWidth()/(image.getHeight()/440.0), 440);
}

I think that should do it, but I'm kind of tired right now...


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.