1. Create an image compression class.
Public Image resourceimage;
Public String errormessage;
Public imagethumbnail (string imagefilename)
{
Resourceimage = image. fromfile (imagefilename );
Errormessage = string. empty;
}
Public bool thumbnailcallback ()
{
Return false;
}
/// <Summary>
/// Method 1: You can customize the image height and width.
/// </Summary>
/// <Param name = "width"> image width </param>
/// <Param name = "height"> image height </param>
/// <Param name = "targetfilepath"> image path </param>
/// <Returns> </returns>
Public bool performancedimage (INT width, int height, string targetfilepath)
{
# Region // method for processing thumbnails
Try
{
Image cecedimage;
Image. getthumbnailimageabort callb = new image. getthumbnailimageabort (thumbnailcallback );
Performancedimage = resourceimage. getthumbnailimage (width, height, callb, intptr. Zero );
Performancedimage. Save (@ targetfilepath, imageformat. JPEG );
Cecedimage. Dispose ();
Return true;
}
Catch (exception E)
{
Errormessage = E. message;
Systemerrorlogbll. insererrorlog (E. Message + ":" + E. Source + ":" + E. targetsite + ": imagethumbnail. cecedimage () method exception in processing thumbnails ");
Return false;
}
# Endregion
}
# Region
Method 2: scale down by percentage by 60% percent to 0.6 targetfilepath as the target path
Public bool performancedimage (double percent, string targetfilepath)
{
Try
{
Image cecedimage;
Image. getthumbnailimageabort callb = new image. getthumbnailimageabort (thumbnailcallback );
Imagewidth = convert. toint32 (resourceimage. Width * percent );
Imageheight = (resourceimage. Height) * imagewidth/resourceimage. width; // proportional Scaling
Performancedimage = resourceimage. getthumbnailimage (imagewidth, imageheight, callb, intptr. Zero );
Performancedimage. Save (@ targetfilepath, imageformat. JPEG );
Cecedimage. Dispose ();
Return true;
}
Catch (exception E)
{
Errormessage = E. message;
Return false;
}
}
2. Call: imagethumbnail imgy = new imagethumbnail (image path );
Imgy. cecedimage (, generating location );
Through tests, it is found that the effect of images generated in a lifetime is better than that of method 2. If you need images to achieve better results, you can use graphics to draw thumbnails for further modification.