c# 将图片切割成小图
private void button1_Click(object sender, EventArgs e)
{
Bitmap orgBitmap = new Bitmap(txtImgPath.Text);
int imgWidth = orgBitmap.Width / 10;
int imgHeingt = orgBitmap.Height / 10;
Bitmap copyBitmap = new Bitmap(imgWidth,imgHeingt);
for (int widthIndex = 0; widthIndex < 10; widthIndex++)
{
for (int heingtIndex = 0; heingtIndex < 10; heingtIndex++)
{
copyBitmap = orgBitmap.Clone(new Rectangle(widthIndex * imgWidth, heingtIndex * imgHeingt, copyBitmap.Width, copyBitmap.Height), PixelFormat.Undefined);
string path = Application.StartupPath + "\\Images\\" + DateTime.Now.ToString("yyyyMMdd") + "\\";
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
string filename = "image" + widthIndex.ToString() + "_" + heingtIndex.ToString() + ".png";
copyBitmap.Save(path + filename, ImageFormat.Png);
}
}
}