Easy Algorithm for proportional Image Scaling

Source: Internet
Author: User

Public struct picsize
{
Public int width;
Public int height;
}
Public static picsize adjustsize (INT spcwidth, int spcheight, int orgwidth, int orgheight)
{
Picsize size = new picsize ();
// The original width and height are within the specified width and height range and are not processed.
If (orgwidth <= spcwidth & orgheight <= spcheight)
{
Size. width = orgwidth;
Size. Height = orgheight;
}
Else
{
// Obtain the proportional coefficient
Float W = orgwidth/(float) spcwidth;
Float H = orgheight/(float) spcheight;
// The width ratio is greater than the height ratio.
If (W> H)
{
Size. width = spcwidth;
Size. Height = (INT) (W> = 1? Math. Round (orgheight/W): Math. Round (orgheight * w ));
}
// The width ratio is smaller than the height ratio.
Else if (W {
Size. Height = spcheight;
Size. width = (INT) (H> = 1? Math. Round (orgwidth/h): Math. Round (orgwidth * H ));
}
// Ratio of width to height
Else
{
Size. width = spcwidth;
Size. Height = spcheight;
}
}
Return size;
}

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/hanghwp/archive/2009/09/04/4517401.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.