I have not updated for a while, and I am not enthusiastic about learning. I am posting a few tips on Image Processing today, hoping to help you:
(1)how to get each frame in .gif image?
(2) how to obtain the thumbnail of an image?
(3) how to "intercept" the specified area of the image?
Using System. drawing;
Using System. Drawing. drawing2d;
Using System. Drawing. imaging;
Public Class Imagehelper
{
/**/ /// <Summary>
/// Obtain the frames in the image.
/// </Summary>
/// <Param name = "ppath"> Image path </Param>
/// <Param name = "psavepath"> Save path </Param>
Public Void Getframes ( String Ppath, String Psavedpath)
{
Image GIF = Image. fromfile (ppath );
Framedimension FD = New Framedimension (GIF. framedimensionslist [ 0 ]);
// Get the number of frames (GIF images may contain multiple frames, and images of other formats are generally only one frame)
Int Count = GIF. getframecount (FD );
// Save frames in JPEG format
For ( Int I = 0 ; I < Count; I ++ )
{< br> GIF. selectactiveframe (FD, I);
GIF. save (psavedpath + " \ Frame _ " + I + " .. jpg " , imageformat. JPEG);
}
}
/**/ /// <Summary>
/// Retrieve image thumbnails
/// </Summary>
/// <Param name = "ppath"> Image path </Param>
/// <Param name = "psavepath"> Save path </Param>
/// <Param name = "pwidth"> Thumbnail width </Param>
/// <Param name = "pheight"> Thumbnail height </Param>
/// <Param name = "pformat"> Save format, usually JPEG </Param>
Public Void Getsmaller ( String Ppath, String Psavedpath, Int Pwidth, Int Pheight)
{
Try
{
Image smallerimg;
Image originalimg = Image. fromfile (ppath );
Image. getthumbnailimageabort callback = New Image. getthumbnailimageabort (thumbnailcallback );
Smallerimg = Originalimg. getthumbnailimage (pwidth, pheight, callback, intptr. Zero );
Smallerimg. Save (psavedpath + " \ Smaller.jpg " , Imageformat. JPEG );
}
Catch (Exception X)
{
//
}
}
/**/ /// <Summary>
/// Obtain the specified part of the image
/// </Summary>
/// <Param name = "ppath"> Image path </Param>
/// <Param name = "psavepath"> Save path </Param>
/// <Param name = "ppartstartpointx"> Coordinate x value (usually) at the start of drawing the Target Image) </Param>
/// <Param name = "ppartstartpointy"> Coordinate Y value (usually) at the start of drawing the Target Image) </Param>
/// <Param name = "ppartwidth"> Target Image Width </Param>
/// <Param name = "ppartheight"> Target Image Height </Param>
/// <Param name = "porigstartpointx"> Coordinate X at the beginning of the original image capture </Param>
/// <Param name = "porigstartpointy"> Coordinate Y value at the beginning of the original image capture </Param>
/// <Param name = "pformat"> Save format, usually JPEG </Param>
Public Void Getpart ( String Ppath, String Psavedpath, Int Ppartstartpointx, Int Ppartstartpointy, Int Ppartwidth, Int Ppartheight, Int Porigstartpointx, Int Porigstartpointy)
{
Image originalimg = Image. fromfile (ppath );
Bitmap partimg = New Bitmap (ppartwidth, ppartheight );
Graphics graphics = Graphics. fromimage (partimg );
Rectangle destrect = New Rectangle ( New Point (ppartstartpointx, ppartstartpointy ), New Size (ppartwidth, ppartheight )); // Target Location
Rectangle origrect = New Rectangle ( New Point (porigstartpointx, porigstartpointy ), New Size (ppartwidth, ppartheight )); // Source image position (the size of the image captured from the source image is equal to the size of the target image by default)
Graphics. drawimage (originalimg, destrect, origrect, graphicsunit. pixel );
Partimg. Save (psavedpath + " \ Part.jpg " , Imageformat. JPEG );
}
Public Bool Thumbnailcallback ()
{
Return False;
}
}