How to Open and Save Image in a Specific Folder in C# – Visual Studio 2012

17
1



This is a tutorial that explain how to Open/Browse and Save Image in in a Specific Folder C# with Visual Studio 2012.
Download source code :

Nguồn:https://wijstaanvooronzegrondrechten.org/

17 COMMENTS

  1. I managed to get it working. Here is the source code and the procedure for saving the image via SaveFileDialog. private void ButtonSave_Click(object sender, EventArgs e)
    {
    Bitmap bitmap = Save(panel1);
    SaveFileDialog dialog = new SaveFileDialog();
    dialog.Filter = "JPG(*.JPG)|*.jpg";
    if (dialog.ShowDialog() == DialogResult.OK)
    {
    bitmap.Save(dialog.FileName);
    System.Diagnostics.Process.Start(dialog.FileName);
    }
    }

    private static Bitmap Save(Control control)
    {
    Bitmap bitmap = new Bitmap(control.Width, control.Height);
    Graphics graphics = Graphics.FromImage(bitmap);
    Rectangle rect = control.RectangleToScreen(control.ClientRectangle);
    graphics.CopyFromScreen(rect.Location, Point.Empty, control.Size);
    return bitmap;
    }

  2. I can't save because: "System.NullReferenceException" ..
    If I open image and want to save it – it works, but when I want to save some picture I draw (using Graphic), it doesn't work.

  3. How do I do this without open a dialog when I save the file?
    I mean I wanna save the file in a fix path of my project.
    Thanks!

LEAVE A REPLY

Please enter your comment!
Please enter your name here