- This topic helps you to save the image from the pictureBox to system using C# programming.
- Save the image is done with the help of SaveFileDialog component in your application.
- You can save the image in any format.
- Tools Needed: Button1 (Button1), SaveFileDialog1 (SaveFileDialog1), PictureBox1 (PictureBox1).
SaveFileDialog Class – Save the image to system from PictureBox in C#
- Help the user to select a location for saving a file.
- This class cannot be inherited.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
- Syntax for SaveFileDialog
|
1 2 3 |
// Declaration public sealed class SaveFileDialog : FileDialog { } |
CommonDialog.ShowDialog Method – Save the image to system from PictureBox in C#
- Help to run a common dialog box with a default owner.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
- Syntax for ShowDialog
|
1 2 3 |
// Declaration public void ShowDialog(void As, void DialogResult) { } |
FileDialog.FileName Property – Save the image to system from PictureBox in C#
- Helps to sets a string containing the file name selected in the file dialog box.
- Syntax
|
1 2 3 |
// Declaration public string FileName { } |
FileDialog.Filter Property – Save the image to system from PictureBox in C#
- Help to get or set the current file name filter string, which determines the choices that appear in the “Save as file type” or “Files of type” box in the dialog box.
- The file filtering options are available in the dialog box.
FileDialog.Title Property – Save the image to system from PictureBox in C#
- Help to assign the file dialog box title
- Syntax
|
1 2 |
'Declaration Public Property Title As String |
SaveFileDialog.OpenFile Method – Save the image to system from PictureBox in C#
- Helps to open the file with read or write permission selected by the user.
- Syntax
|
1 2 |
'Declaration Public Function OpenFile As Stream |
Save the image to system from PictureBox in C# – Complete Code
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif"; saveFileDialog1.Title = "Save an Image File"; saveFileDialog1.ShowDialog(); if (!string.IsNullOrEmpty(saveFileDialog1.FileName)) { System.IO.FileStream fs = (System.IO.FileStream)saveFileDialog1.OpenFile(); switch (saveFileDialog1.FilterIndex) { case 1: this.PictureBox1.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg); break; case 2: this.PictureBox1.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Bmp); break; case 3: this.PictureBox1.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Gif); break; } fs.Close(); } } } } |
C# PictureBox - Related Topics
- Add PictureBox control dynamically to the form using C#
- Save the image to system from PictureBox in C#
- Color text with moving color gradient in C#
- Draw border around PictureBox in C#
- Drag image in PictureBox through the form in C#
- How to zoom picture in picturebox in C#
- Add picture to RichTextBox from a PictureBox in C#
- How to Drag and Drop Picture to PictureBox in C#
- Capture screenshot from Desktop and crop it in C#
- Move PictureBox Up and Down in form in C#
- Rotate an image in PictureBox in C#
C# SaveFileDialog - Related Topics
C# Files and Directory - Related Topics
Save the image to system from PictureBox in C#






