2
Answers

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:

 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() != "")
{
pictureBox1.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

Answers (2)