You have a method that accepts two strings: one the source image, the other the filename you want to save the new copy as. Presently, you are calling it with hard coded strings - but the method doesn't care what you pass it, provided that they are strings and that one of them "points at" the source image file. So just replace the hardcode path and filename with variables and call the same method.
Me? I'd write three methods:
private Image LoadImage(string path)
{
using (Image im = Image.FromFile(path))
{
return new Bitmap(im);
}
}
private string GetImageFullPath(string name)
{
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads", name);
}
private void SaveImage(Image im, string destPath)
{
im.Save(destPath, System.Drawing.Imaging.ImageFormat.Png);
}
And use them.
Note: Your original
try ... catch
block is irrelevant: it does nothing useful at all.