Monday, April 2, 2012

How to load , rename and save image in a folder in c#

[sourcecode language="csharp"]
private void Load_Click(object sender, EventArgs e)
{
openFD.Title = "Insert an image ";
openFD.InitialDirectory = "c:";
openFD.FileName = "";
openFD.Filter = "JPEG Image|*.jpg|GIF Image|*.gif|PNG Image|*.png";
openFD.Multiselect = false;
if (openFD.ShowDialog() != DialogResult.OK)
return;

//display image in pic box
pictureBox1.ImageLocation = openFD.FileName;

}

private void Copy_Click(object sender, EventArgs e)
{
const string new_dir = @"C:\Users\Public\Pictures\Sample Pictures\";
MessageBox.Show(openFD.FileName);
string extension = System.IO.Path.GetExtension(openFD.FileName);
string renamed_name = id + "" + extension;
string fName = System.IO.Path.Combine(new_dir,renamed_name );
if (File.Exists(fName))
File.Delete(fName);
System.IO.File.Copy(openFD.FileName, fName);
string msg = string.Format("Copied {0} to {1}",openFD.FileName,   fName);
MessageBox.Show(msg, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);

}
[/sourcecode]

No comments:

Post a Comment

How to enable CORS in Laravel 5

https://www.youtube.com/watch?v=PozYTvmgcVE 1. Add middleware php artisan make:middleware Cors return $next($request) ->header('Acces...