C # proportional scaling of images,
// Proportional scaling of the Image public Image ZoomPicture (Image SourceImage, int TargetWidth, int TargetHeight) {int IntWidth; // The New Image Width int IntHeight; // New Image Height try {System. drawing. imaging. imageFormat format = SourceImage. rawFormat; System. drawing. bitmap SaveImage = new System. drawing. bitmap (TargetWidth, TargetHeight); Graphics g = Graphics. fromImage (SaveImage); g. clear (Color. white); // calculate the scaled image size http://www.cnblogs.com/roucheng/ If (SourceImage. width> TargetWidth & SourceImage. height <= TargetHeight) // The width of the target image is greater than that of the target image. The length is smaller than that of the target image. {IntWidth = TargetWidth; IntHeight = (IntWidth * SourceImage. height)/SourceImage. width;} else if (SourceImage. width <= TargetWidth & SourceImage. height> TargetHeight) // The width of the target image is smaller than that of the target image. The length is larger than that of the target image. {IntHeight = TargetHeight; IntWidth = (IntHeight * SourceImage. width)/SourceImage. height;} else if (SourceImage. width <= TargetWidth & SourceImage. height <= TargetHeight) // the aspect ratio. The length and width of the target image are both small {IntHeight = SourceImage. width; IntWidth = SourceImage. height;} else // the length and width of the target image are both large {IntWidth = TargetWidth; IntHeight = (IntWidth * SourceImage. height)/SourceImage. width; if (IntHeight> TargetHeight) // re-calculate {IntHeight = TargetHeight; IntWidth = (IntHeight * SourceImage. width)/SourceImage. height;} g. drawImage (SourceImage, (TargetWidth-IntWidth)/2, (TargetHeight-IntHeight)/2, IntWidth, IntHeight); SourceImage. dispose (); return SaveImage;} catch (Exception ex) {} return null ;}