public void MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height)
{
//Get the original picture
originalImage = (originalImagePath);
//Thumbnail canvas width and height
int towidth = width;
int toheight = height;
//Writing the original image to the canvas coordinates and width and height (used to set the clipping overflow part)
int x = 0;
int y = 0;
int ow = ;
int oh = ;
//Original picture canvas, set the coordinates and width and height of the writing thumbnail picture canvas (used to scale the overall width and height of the original picture)
int bg_x = 0;
int bg_y = 0;
int bg_w = towidth;
int bg_h = toheight;
//Multiple variable
double multiple = 0;
//Get the width or length or multiples of height and thumbnail
if ( >= )
multiple = (double) / (double)width;
else
multiple = (double) / (double)height;
//The width and height of the uploaded image are equal to the thumbnail
if (ow <= width && oh <= height)
{
//Thumbnail image according to its original width and height
bg_w = ;
bg_h = ;
//The blank part is filled with background color
bg_x = Convert.ToInt32(((double)towidth - (double)ow) / 2);
bg_y = Convert.ToInt32(((double)toheight - (double)oh) / 2);
}
//The width and height of the uploaded image are larger than the thumbnail
else
{
//The width and height are scaled to scale
bg_w = Convert.ToInt32((double) / multiple);
bg_h = Convert.ToInt32((double) / multiple);
//The blank part is filled with background color
bg_y = Convert.ToInt32(((double)height - (double)bg_h) / 2);
bg_x = Convert.ToInt32(((double)width - (double)bg_w) / 2);
}
//Create a new bmp image and set the thumbnail size.
bitmap = new (towidth, toheight);
// Create a new artboard
g = (bitmap);
//Set high-quality interpolation method
= .;
//Set high quality and low speed to show smoothness
= .;
//Clear the canvas and set the background color
(("#F2F2F2"));
//Draw the specified part of the original picture at the specified location and according to the specified size.
//The first is the canvas coordinates and width and height of the original picture, the second is the coordinates and width and height of the original picture written on the canvas, and the last parameter is the specified numerical unit as pixels.
(originalImage, new (bg_x, bg_y, bg_w, bg_h), new (x, y, ow, oh), );
try
{
//Get picture type
string fileExtension = (originalImagePath).ToLower();
//Save thumbnail images according to the original image type. If the picture does not follow the original format, there will be problems such as blurring and jagging.
switch (fileExtension)
{
case ".gif": (thumbnailPath, ); break;
case ".jpg": (thumbnailPath, ); break;
case ".bmp": (thumbnailPath, ); break;
case ".png": (thumbnailPath, ); break;
}
}
catch ( e)
{
throw e;
}
finally
{
();
();
();
}
}