所以我在 C# 中创建了一个程序,它获取图像并将其拆分为图块。我正处于想要拍摄大图像并将其切成不同的图块并保存每个图块的地步。我遇到的问题是它适用于第一个图块,但所有其他图块都是空白的,我不知道为什么。这是我正在砍的代码。
Graphics g;
Image tempTile;
TextureBrush textureBrush;
int currRow = 1;
int currCol = 1;
int currX = 0; //Used for splitting. Initialized to origin x.
int currY = 0; //Used for splitting. Initialized to origin y.
//Sample our new image
textureBrush = new TextureBrush(myChopImage);
while (currY < myChopImage.Height)
{
while (currX < myChopImage.Width)
{
//Create a single tile
tempTile = new Bitmap(myTileWidth, myTileHeight);
g = Graphics.FromImage(tempTile);
//Fill our single tile with a portion of the chop image
g.FillRectangle(textureBrush, new Rectangle(currX, currY, myTileWidth, myTileHeight));
tempTile.Save("tile_" + currCol + "_" + currRow + ".bmp");
currCol++;
currX += myTileWidth;
g.Dispose();
}
//Reset the current column to start over on the next row.
currCol = 1;
currX = 0;
currRow++;
currY += myTileHeight;
}