private void buttonGenerate_Click(object sender, EventArgs e)
{
if (pictureBoxImage.Image == null)
{
MessageBox.Show("Please select an image.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
int columns;
if (string.IsNullOrEmpty(textBoxColumns.Text))
{
columns = pictureBoxImage.Image.Width;
textBoxColumns.Text = columns.ToString();
}
else
{
if (!int.TryParse(textBoxColumns.Text, out columns))
{
MessageBox.Show("Illegal integer format: \"Columns\".", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
int lines;
if (string.IsNullOrEmpty(textBoxLines.Text))
{
lines = pictureBoxImage.Image.Height;
textBoxLines.Text = lines.ToString();
}
else
{
if (!int.TryParse(textBoxLines.Text, out lines))
{
MessageBox.Show("Illegal integer format: \"Lines\".", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
float font_size;
if (string.IsNullOrEmpty(textBoxFontSize.Text))
{
font_size = 9.0f;
textBoxFontSize.Text = font_size.ToString();
}
else
{
if (!float.TryParse(textBoxFontSize.Text, out font_size))
{
MessageBox.Show("Illegal float format: \"Font Size\".", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
result_form.ResultFont = new Font(comboBoxFontFamily.Text, font_size);
using (Graphics graphics = this.CreateGraphics())
{
result_form.ResultText = ASCIIArt.Generate(graphics, new Bitmap(pictureBoxImage.Image, columns, lines), result_form.ResultFont, new HashSet<char>(ascii));
}
result_form.ShowDialog();
}