Image cutting is to cut a large image into multiple small images according to user requirements. In the DOTNET environment, the system provides the GDI + class library, which provides a convenient interface for image operation and processing.
The following is an image cutting Applet:
Public class imagemanager
{
/// <Summary>
/// Image Cutting
/// </Summary>
/// <Param name = "url"> image file name </param>
/// <Param name = "width"> width of the image after cutting </param>
/// <Param name = "height"> height of the image after cutting </param>
/// <Param name = "savepath"> Save path of the image file after cutting </param>
/// <Param name = "fileext"> image file extension after cutting </param>
Public static void cut (string URL, int width, int height, string savepath, string fileext, string logofile)
{
Bitmap bitmap = new Bitmap (URL );
Decimal maxrow = math. Ceiling (decimal) bitmap. Height/height );
Decimal maxcolumn = math. Ceiling (decimal) bitmap. width/width );
For (decimal I = 0; I <maxrow; I ++)
{
For (decimal J = 0; j <maxcolumn; j ++)
{
String filename = I. tostring () + "," + J. tostring () + "." + fileext;
Bitmap BMP = new Bitmap (width, height );
For (INT offsetx = 0; offsetx <width; offsetx ++)
{
For (INT offsety = 0; offsety {
If (J * width + offsetx) <bitmap. width) & (I * height + offsety) <bitmap. Height ))
{
BMP. setpixel (offsetx, offsety, bitmap. getpixel (INT) (J * width + offsetx), (INT) (I * height + offsety )));
}
}
}
Graphics G = graphics. fromimage (BMP );
G. drawstring ("zhehui technology", new font ("", 20), new solidbrush (color. fromargb (70, color. whitesmoke), 60, height/2); // Add a watermark
Imageformat format = imageformat. PNG;
Switch (fileext. tolower ())
{
Case "PNG ":
Format = imageformat. PNG;
Break;
Case "BMP ":
Format = imageformat. BMP;
Break;
Case "GIF ":
Format = imageformat. gif;
Break;
}
BMP. Save (savepath + "//" + filename, format );
}
}
}
}
Programmers only need to call the cut function to apply it.