There are four overload methods in it, some that directly return the image object, some that generate thumbnails, and save them to the specified directory!
Using system. IO;
Using system. drawing;
Using system. Drawing. imaging;
/// <Summary>
/// Image Processing
/// 1. Generate a thumbnail or change the image size and image quality in proportion.
/// 2. Place the generated thumbnail in the specified directory.
/// </Summary>
Public class imageclass
{
Public Image resourceimage;
Private int imagewidth;
Private int imageheight;
Public String errmessage;
/// <Summary>
/// Constructor of the class
/// </Summary>
/// <Param name = "imagefilename"> full path name of the image file </param>
Public imageclass (string imagefilename)
{
Resourceimage = image. fromfile (imagefilename );
Errmessage = "";
}
Public bool thumbnailcallback ()
{
Return false;
}
/// <Summary>
/// Method 1 for generating thumbnail overloading. The image object of the thumbnail is returned.
/// </Summary>
/// <Param name = "width"> width of the thumbnail </param>
/// <Param name = "height"> height of the thumbnail </param>
/// <Returns> thumbnail image object </returns>
Public Image getreducedimage (INT width, int height)
{
Try
{
Image cecedimage;
image. getthumbnailimageabort callb = new image. getthumbnailimageabort (thumbnailcallback);
performancedimage = resourceimage. getthumbnailimage (width, height, callb, intptr. zero);
return reducedimage;
}< br> catch (exception e)
{< br> errmessage = E. message;
return NULL;
}< BR >}
///
// method 2 for generating thumbnail Overloading, save the thumbnail file to the specified path
///
/// width of the thumbnail
/// height of the thumbnail
/// the full file name saved by the thumbnail, (With path), parameter format: D: \ images \ filename.jpg
// success returns true, otherwise, false is returned.
Public bool getreducedimage (INT width, int height, string targetfilepath)
{< br> try
{< br> image performancedimage;
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)
{
Errmessage = E. message;
Return false;
}
}
/// <Summary>
/// Method 3 for generating thumbnail overloading. The image object of the thumbnail is returned.
/// </Summary>
/// <Param name = "percent"> set the width percentage of the thumbnail to 0.8 if the width percentage is 80. </param>
/// <Returns> thumbnail image object </returns>
Public Image getreducedimage (double percent)
{
Try
{
Image cecedimage;
Image. getthumbnailimageabort callb = new image. getthumbnailimageabort (thumbnailcallback );
imagewidth = convert. toint32 (resourceimage. width * percent);
imageheight = convert. toint32 (resourceimage. width * percent);
performancedimage = resourceimage. getthumbnailimage (imagewidth, imageheight, callb, intptr. zero);
return reducedimage;
}< br> catch (exception e)
{< br> errmessage = E. message;
return NULL;
}< BR >}
/// <Summary>
/// Method 4 for generating thumbnail overloading. The image object of the thumbnail is returned.
/// </Summary>
/// <Param name = "percent"> set the width percentage of the thumbnail to 0.8 if the width percentage is 80. </param>
/// <Param name = "targetfilepath"> full file name saved by the thumbnail (with Path). Parameter format: D: \ images \ filename.jpg </param>
/// <Returns> success returns true; otherwise, false is returned. </returns>
Public bool getreducedimage (double percent, string targetfilepath)
{
Try
{
Image cecedimage;
Image. getthumbnailimageabort callb = new image. getthumbnailimageabort (thumbnailcallback );
Imagewidth = convert. toint32 (resourceimage. Width * percent );
Imageheight = convert. toint32 (resourceimage. Width * percent );
Performancedimage = resourceimage. getthumbnailimage (imagewidth, imageheight, callb, intptr. Zero );
Performancedimage. Save (@ targetfilepath, imageformat. JPEG );
Cecedimage. Dispose ();
Return true;
}
Catch (exception E)
{
Errmessage = E. message;
Return false;
}
}
}