There are 4 heavy load methods, there is a direct return image, there is a generated thumbnail, and save it to the specified directory!
Using system.io; using system.drawing.image;
/// /// Picture Process Class /// 1, generate a thumbnail image or change the size and picture quality /// 2 of the picture according to the ratio, and put the generated thumbnail to the specified directory ///// summary> public class imageclass {public image resourceImage; private int imageHeight;
PUBLIC STRING ERRMESSAGE;
/// /// summary> /// Image file full path name param> public imageclass (string imagefilename) {resourceImage = Image.fromfile (imagefilename); errmessage = "";
Public Bool thumbnailcallback () {Return False;}
/// /// Generates a thumbnail overload method 1, returns the image object /// summary> /// thumbnail param> / // thumbnails of the Image Objects RETURNS> PUBLIC Image GetReducedImage (Int Width, Int Height);
Image.GetThumbnailImageAbort callb = new Image.GetThumbnailImageAbort (ThumbnailCallback); ReducedImage = ResourceImage.GetThumbnailImage (Width, Height, callb, IntPtr.Zero); return ReducedImage;} catch (Exception e) {ErrMessage = e.Message; return null;} }
/// /// Generate a thumbnail overload method 2, save the thumbnail file to the specified path /// summary> /// The width of the thumbnail Param> /// thumbnail param> /// thumbnail saved full file name, (with path), parameter format: D: / Images / filename.jpg param> /// returns true if successful, otherwise returns false returns> public bool GetReducedImage (int Width, int Height, string targetFilePath) {try {Image ReducedImage; Image.GetThumbnailImageAbort callb = new Image.GetThumbnailImageAbort (ThumbnailCallback); ReducedImage = ResourceImage.GetThumbnailImage (Width, Height, callb, IntPtr.Zero); ReducedImage.Save (@ targetFilePath, ImageFormat.Jpeg);
Reducedimage.dispose (); return true;} catch (exception e) {errmessage = E.MESSAGE; RETURN FALSE;}}
/// /// Generates a thumbnail overload method 3, returns the image object /// summary> /// thumbnail, such as: In 80, fill in 0.8 param> /// thumbnails return object returns> public image getreducedImage (image reducedimage);
Image.getthumbnailimageabort callb = new image.getthumbnailImageabort (thumbnailcallback);
ImageWidth = Convert.ToInt32 (ResourceImage.Width * Percent); ImageHeight = Convert.ToInt32 (ResourceImage.Width * Percent); ReducedImage = ResourceImage.GetThumbnailImage (ImageWidth, ImageHeight, callb, IntPtr.Zero); return ReducedImage;} catch (Exception e) {errmessage = E.Message; return null;}}
/// /// Generates a thumbnail overload method 4, returns the image object /// summary> /// thumbnail, such as: Need 100 In the 80th, fill in 0.8 param> /// Thumbnail saved full file name, (with path), parameter format: D: /images/filename.jpg param> / // successful return true, otherwise returns false returns> public bool GetReducedImage (double Percent, string targetFilePath) {try {Image ReducedImage; Image.GetThumbnailImageAbort callb = new Image.GetThumbnailImageAbort (ThumbnailCallback);
ImageWidth = Convert.ToInt32 (ResourceImage.Width * Percent); ImageHeight = Convert.ToInt32 (ResourceImage.Width * Percent); ReducedImage = ResourceImage.GetThumbnailImage (ImageWidth, ImageHeight, callb, IntPtr.Zero);
Reducedimage.save (@ target.jpeg); reducedimage.dispose (); return true;} catch (exception e) {errmessage = E.MESSAGE; RETURN FALSE;}}
}