RSS

Tag Archives: copy image

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

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);

}
 
Leave a comment

Posted by on April 2, 2012 in C#.Net

 

Tags: , , ,

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

Drag an OpenFileDialog to the form

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\"; //destination folder
string fName = System.IO.Path.Combine(new_dir, System.IO.Path.GetFileName(openFD.FileName));
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);

}
 
Leave a comment

Posted by on April 2, 2012 in C#.Net

 

Tags: , ,