private void btnSplit_Click(object sender, EventArgs e)
{
if (Resource != null)
{
btnSplit.Visible = false;
if (!Directory.Exists(txtOutputPath.Text))
{
Directory.CreateDirectory(txtOutputPath.Text);
}
var srcExt = txtFile.Text.Substring(
txtFile.Text.LastIndexOf(".") + 1);
var srcName = txtFile.Text.Substring(
txtFile.Text.LastIndexOf(Path.DirectorySeparatorChar) + 1).Replace("." + srcExt, string.Empty);
var cols = ((int)numericX.Value >= 1) ? (int)numericX.Value : 1;
var rows = ((int)numericY.Value >= 1) ? (int)numericY.Value : 1;
var width = (int)Resource.Image.Size.X / cols;
var height = (int)Resource.Image.Size.Y / rows;
for (int r = 0; r < rows; r++)
{
for (int c = 0; c < cols; c++)
{
var destName = txtOutputFormat.Text.Replace(
"%f", srcName).Replace(
"%ext", srcExt).Replace(
"%r", r.ToString()).Replace(
"%c", c.ToString()).Replace(
"%t", ((r * cols) + c).ToString());
Image image = new Image((uint)width, (uint)height);
image.Copy(Resource.Image, 0, 0, new IntRect(c * width, r * height, width, height));
image.SaveToFile(txtOutputPath.Text + destName);
image?.Dispose();
image = null;
Application.DoEvents();
}
}
btnSplit.Visible = true;
}
txtFile.Focus();
}