Monday, April 2, 2012

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

Drag an OpenFileDialog to the form

[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\"; //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);

}
[/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...