Simple GDI + processing image size (C # code)

Source: Internet
Author: User
/// <Summary>
/// Scale the image
/// </Summary>
/// <Param name = "IMG"> original image </param>
/// <Param name = "xwith"> zoom in/out ratio. The image size is smaller than 100. </param>
/// <Param name = "yheight"> proportional scaling </param>
/// <Returns> return the processed image </returns>
Public Image scaleimg (system. Drawing. Image IMG, int xwith, int yheight)
{
// Calculate the image width after processing
Int I = convert. toint32 (IMG. Width * xwith/100 );
// The Image Height after computing and Processing
Int J = convert. toint32 (IMG. Height * yheight/100 );
// Format the image
System. Drawing. Image imgscale = new system. Drawing. Bitmap (I, j, system. Drawing. imaging. pixelformat. format24bpprgb );
System. Drawing. Graphics G = system. Drawing. Graphics. fromimage (imgscale );
System. Drawing. Rectangle srcrect = new system. Drawing. rectangle (0, 0, IMG. Width, IMG. Height );
System. Drawing. Rectangle desrect = new system. Drawing. rectangle (0, 0, imgscale. Width, imgscale. Height );
G. Clear (system. Drawing. color. White );
G. drawimage (IMG, desrect, srcrect, system. Drawing. graphicsunit. pixel );
// Save the processed image as another one
Imgscale. Save ("E: \ 1111.jpg", system. Drawing. imaging. imageformat. GIF );
G. Dispose ();
Return imgscale;
}

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.