Use GetThumbnailImage for Image Scaling

Source: Internet
Author: User

/// <Summary>
/// Method for obtaining proportional scaling Images
/// </Summary>
/// <Param name = "imgPath"> image path to be scaled </param>
/// <Param name = "savePath"> resize the image storage path </param>
/// <Param name = "format"> resize the image storage format </param>
/// <Param name = "scaling"> width or height to be kept </param>
/// <Param name = "keepWidthOrHeight"> if it is true, the width is scaling; otherwise, the height is scaling. </param>
/// <Returns> </returns>
Public bool GetThumbnail (string imgPath, string savePath, ImageFormat format, int scaling, bool keepWidthOrHeight)
{
Try
{
Using (Bitmap myBitmap = new Bitmap (imgPath ))
{
Int width = 0;
Int height = 0;
Int tw = myBitmap. Width; // The actual Width of the image.
Int th = myBitmap. Height; // The actual Height of the image
If (keepWidthOrHeight) // keep the width
{
# Region auto-retain width
If (scaling> = tw)
{
Width = tw;
Height = th;
}
Else
{
Double ti = Convert. ToDouble (tw)/Convert. ToDouble (scaling );
If (ti = 0d)
{
Width = tw;
Height = th;
}
Else
{
Width = scaling;
Height = Convert. ToInt32 (Convert. ToDouble (th)/ti );
}
}
# Endregion
}
& Nb

Related Article

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.