By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,221 Members | 1,663 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,221 IT Pros & Developers. It's quick & easy.

How to save image from picturebox using c#

P: 19
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:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace OpenSaveImage
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.  
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         Bitmap OriginalImage;
  21.  
  22.  
  23.         private void btnOpen_Click(object sender, EventArgs e)
  24.         {
  25.             //Open File Dialog to load image files
  26.             openFileDialog1.FileName = "";
  27.             openFileDialog1.Title = "Images";
  28.  
  29.             //Filter the filedialog, so that it will show only the mentioned format images
  30.             openFileDialog1.Filter = "PNG Image(*.png)|*.png|JPG Image(*.jpg)|*.jpg|BMP Image(*.bmp)|*.bmp";
  31.             openFileDialog1.ShowDialog();
  32.  
  33.             if (openFileDialog1.FileName.ToString() != "")
  34.             {
  35.                 Box1.ImageLocation = openFileDialog1.FileName.ToString();
  36.                 OriginalImage = new Bitmap(openFileDialog1.FileName.ToString());
  37.             }
  38.  
  39.             butSave.Enabled = true;
  40.         }
  41.  
  42.        // private void butSave_Click(object sender, EventArgs e)
  43.        // {
  44.          //   SaveFileDialog saveFileDialog1 = new SaveFileDialog();
  45.          //   saveFileDialog1.Filter = "PNG Image(*.png)";
  46.          //   if (saveFileDialog1.ShowDialog() == DialogResult.OK)
  47.          //   {
  48.                 //saveImg(saveFileDialog1.FileName, new Bitmap(OriginalImage), 85L);
  49.          //   }
  50.     //    }
  51.  
  52.  
  53.         /*
  54.          * Code for save image
  55.          */
  56.  
  57.  
  58.  
  59.     }
  60. }
  61.  
hope someone could help me, thank you
Aug 4 '10 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 218
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
Aug 4 '10 #2

Curtis Rutland
Expert 2.5K+
P: 3,256
Image.Save lets you specify an image format.
Aug 4 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.