C# Save Image From PictureBox to a Folder

How To Store an Image From PictureBox To a directory Using C#

Save Picture From PictureBox Using C#

In This C# Tutorial  We Will See How To Upload a Picture To a PictureBox Control on a Button Click Event And Save The Image Into a Specific Folder With a Customize Name In Csharp Programming Language And Visual Studio Editor.


Project Source Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Imaging;

namespace Csharp_Tutorials
{
    public partial class save_image_from_picturebox : Form
    {
        public save_image_from_picturebox()
        {
            InitializeComponent();
        }

        // upload image 
        private void buttonUpload_Click(object sender, EventArgs e)
        {
            OpenFileDialog opf = new OpenFileDialog();

            // chose the images type
            opf.Filter = "Choose Image(*.jpg;*.png;*.gif)|*.jpg;*.png;*.gif";

            if (opf.ShowDialog() == DialogResult.OK)
            {
                // get the image returned by OpenFileDialog 
                pictureBox1.Image = Image.FromFile(opf.FileName);
            }
        }

        // button save
        private void buttonSave_Click(object sender, EventArgs e)
        {

            SaveFileDialog svf = new SaveFileDialog();

            // set a default name using date and time
            string imgName = DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.Hour + "_" + DateTime.Now.Second + "." + ImageFormat.Jpeg;

            svf.FileName = imgName;

            if(svf.ShowDialog() == DialogResult.OK)
            {
                pictureBox1.Image.Save(svf.FileName);
            }

        }
    }
}


      

///////////////OUTPUT:

save picture using c#




Share this

Related Posts

Previous
Next Post »