How to save image from picturebox using c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aznimah
    New Member
    • Nov 2009
    • 19

    #1

    How to save image from picturebox using c#

    Hi,

    i need help on how to save the image that return from picturebox?

    basically the program works,
    1)Read image (.png)--> load into pictureBox1
    2)Fire button save to save the image from pictureBox1

    Here i place code:

    Code:
    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 OpenSaveImage
    {
        public partial class Form1 : Form
        {
            
            public Form1()
            {
                InitializeComponent();
            }
    
            Bitmap OriginalImage;
    
         
            private void btnOpen_Click(object sender, EventArgs e)
            {
                //Open File Dialog to load image files
                openFileDialog1.FileName = "";
                openFileDialog1.Title = "Images";
    
                //Filter the filedialog, so that it will show only the mentioned format images
                openFileDialog1.Filter = "PNG Image(*.png)|*.png|JPG Image(*.jpg)|*.jpg|BMP Image(*.bmp)|*.bmp";
                openFileDialog1.ShowDialog();
    
                if (openFileDialog1.FileName.ToString() != "")
                {
                    Box1.ImageLocation = openFileDialog1.FileName.ToString();
                    OriginalImage = new Bitmap(openFileDialog1.FileName.ToString());
                }
    
                butSave.Enabled = true;
            }
    
           // private void butSave_Click(object sender, EventArgs e)
           // {
             //   SaveFileDialog saveFileDialog1 = new SaveFileDialog();
             //   saveFileDialog1.Filter = "PNG Image(*.png)";
             //   if (saveFileDialog1.ShowDialog() == DialogResult.OK)
             //   {
                    //saveImg(saveFileDialog1.FileName, new Bitmap(OriginalImage), 85L);
             //   }
        //    }
    
    
            /*
             * Code for save image
             */
            
        
    
        }
    }
    hope someone could help me, thank you
    Last edited by Curtis Rutland; Aug 4 '10, 02:04 PM. Reason: Fixed small code tag issue.
  • Christian Binder
    Recognized Expert New Member
    • Jan 2008
    • 218

    #2
    Try
    Box1.Image.Save (filename);

    But I don't know if it converts automatically to png if you load another Image.
    Mabye you look at msdn

    Comment

    • Curtis Rutland
      Recognized Expert Specialist
      • Apr 2008
      • 3264

      #3
      Image.Save lets you specify an image format.

      Comment

      Working...