That's all there is to this simple program. There's a button, you open an image file, the program puts a watersign on it and overwrites it:
private void button1_Click(object sender, EventArgs e)
{
var openDialog = new OpenFileDialog();
var dialogResult = openDialog.ShowDialog();
if (dialogResult == DialogResult.OK)
{
var file = openDialog.FileName;
using (var bmp = new Bitmap((Bitmap)Image.FromFile(file)))
using (var g = Graphics.FromImage(bmp))
{
openDialog.Dispose();
var waterSign = (Bitmap)Properties.Resources.ResourceManager.GetObject("watersign");
var margin = 15;
var x = bmp.Width - waterSign.Width - margin;
var y = bmp.Height - waterSign.Height - margin;
g.DrawImage(waterSign, new Point(x, y));
waterSign.Dispose();
}
try
{
File.Delete(file);
//bmp2.Save("C:\\Temp\\huhu.bmp");
this.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
Right now I'm just trying to delete the damned file which for some reason doesn't work. I tried using as you can see, as well as Dispose(), as well as creating another BMP which gets its data from the first one.
Any ideas? Thanks in advance!