By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,635 Members | 1,703 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,635 IT Pros & Developers. It's quick & easy.

Image scaling by Width & Height constant - preserve aspect ratio

P: n/a
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
Jul 17 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Farce Milverk wrote:
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

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...
Jul 17 '06 #2

P: 5
Hi,
I want to print the screen ie(768*1024).For this I have capture the screen in to a BufferedImage.Now when I try to print it doesnt print completely.So please guide me how do I scale it and print.
My code :
Rectangle area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSiz e());
Graphics2D g2d= (Graphics2D)g;
BufferedImage img= robot.createScreenCapture(area);
g2d.drawImage(img,0,0,null);

Latheef
Jul 22 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.