Copy Code code as follows:
Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using System.IO;
Using System.Drawing;
Using System.Drawing.Imaging;
<summary>
Picture Processing class
1. Generate thumbnail images or change the size and quality of pictures proportionally
2. Place the generated thumbnail in the specified directory
</summary>
public class Imageclass
{
Public System.Drawing.Image Resourceimage;
private int imagewidth;
private int imageheight;
public string errmessage;
<summary>
Constructors for classes
</summary>
<param name= "Imagefilename" > Picture file full path name </param>
Public Imageclass (String imagefilename)
{
Resourceimage = System.Drawing.Image.FromFile (imagefilename);
Errmessage = "";
}
public bool Thumbnailcallback ()
{
return false;
}
<summary>
Generate thumbnail overload Method 1, returning the image object of the thumbnail
</summary>
<param name= "width" > thumbnail widths </param>
<param name= "height" > Thumbnail Heights </param>
<returns> thumbnail Image Object </returns>
Public System.Drawing.Image getreducedimage (int Width, int Height)
{
Try
{
System.Drawing.Image Reducedimage;
System.Drawing.Image.GetThumbnailImageAbort callb = new System.Drawing.Image.GetThumbnailImageAbort ( Thumbnailcallback);
Reducedimage = Resourceimage.getthumbnailimage (Width, Height, CALLB, IntPtr.Zero);
return reducedimage;
}
catch (Exception e)
{
Errmessage = E.message;
return null;
}
}
<summary>
Generate thumbnail overload Method 2, save the thumbnail file to the specified path
</summary>
<param name= "width" > thumbnail widths </param>
<param name= "height" > Thumbnail Heights </param>
<param name= "Targetfilepath" > Thumbnail saved full-text name, (with path), parameter format: D:images ilename.jpg</param>
<returns> return true successfully, otherwise return false</returns>
public bool Getreducedimage (int Width, int Height, string targetfilepath)
{
Try
{
System.Drawing.Image Reducedimage;
System.Drawing.Image.GetThumbnailImageAbort callb = new System.Drawing.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;
}
}
<summary>
Generate thumbnail overload Method 3, returning the image object of the thumbnail
</summary>
<param name= "Percent" > thumbnail width of the percentage such as: Required 80, to fill 0.8</param>
<returns> thumbnail Image Object </returns>
Public System.Drawing.Image getreducedimage (double Percent)
{
Try
{
System.Drawing.Image Reducedimage;
System.Drawing.Image.GetThumbnailImageAbort callb = new System.Drawing.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;
}
}
<summary>
Generate thumbnail overload method 4, returning the image object of the thumbnail
</summary>
<param name= "Percent" > thumbnail width of the percentage such as: Required 80, to fill 0.8</param>
<param name= "Targetfilepath" > Thumbnail saved full-text name, (with path), parameter format: D:images ilename.jpg</param>
<returns> return true successfully, otherwise return false</returns>
public bool Getreducedimage (double Percent, String targetfilepath)
{
Try
{
System.Drawing.Image Reducedimage;
System.Drawing.Image.GetThumbnailImageAbort callb = new System.Drawing.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 (@targetFilePath, imageformat.jpeg);
Reducedimage.dispose ();
return true;
}
catch (Exception e)
{
Errmessage = E.message;
return false;
}
}
}