public static void CaptureSprite(string texturePath, string spritePath, int offsetX, int offsetY, int width, int height)
{
Bitmap texture = new Bitmap(texturePath);
Bitmap sprite = new Bitmap(width, height);
int sprite_x = 0;
int start_y = texture.Height - offsetY - height;
if (start_y < 0)
{
throw new System.Exception("offsetY 或者 height 错误");
}
for (int x = offsetX; x < width + offsetX; x++)
{
int sprite_y = 0;
for (int y = start_y; y < start_y + height; y++)
{
sprite.SetPixel(sprite_x, sprite_y, texture.GetPixel(x, y));
sprite_y++;
}
sprite_x++;
}
sprite.Save(spritePath);
}
需要替换sprite到texture时,反向操作即可
批量操作时,解析yaml