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;
///
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
///
public class Imageclass
{
Public System.Drawing.Image Resourceimage;
private int imagewidth;
private int imageheight;
public string errmessage;
///
Constructors for classes
///
Full path name of picture file
Public Imageclass (String imagefilename)
{
Resourceimage = System.Drawing.Image.FromFile (imagefilename);
Errmessage = "";
}
public bool Thumbnailcallback ()
{
return false;
}
///
Generate thumbnail overload Method 1, returning the image object of the thumbnail
///
width of thumbnails
The height of the thumbnail
Image object for thumbnail image
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;
}
}
///
Generate thumbnail overload Method 2, save the thumbnail file to the specified path
///
width of thumbnails
The height of the thumbnail
Thumbnail saved full-text name, (with path), parameter format: D:images ilename.jpg
Returns true successfully, otherwise returns false
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;
}
}
///
Generate thumbnail overload Method 3, returning the image object of the thumbnail
///
Percentage of the width of the thumbnail: 80 is required, 0.8.
Image object for thumbnail image
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;
}
}
///
Generate thumbnail overload method 4, returning the image object of the thumbnail
///
Percentage of the width of the thumbnail: 80 is required, 0.8.
Thumbnail saved full-text name, (with path), parameter format: D:images ilename.jpg
Returns true successfully, otherwise returns false
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;
}
}
}