Reputation: 9
I just created a simple webpage in which there is a PictureBox inside a Panel, the PictureBox allow users to import picture, and the Panel allow the user to insert color, so how can i export / save it as .jpeg file?
Upvotes: 0
Views: 193
Reputation: 716
Here is my solution with additional support to various file types:
public void ExportToBmp(string path)
{
using(var bitmap = new Bitmap(pictureBox.Width, pictureBox.Height))
{
pictureBox.DrawToBitmap(bitmap, pictureBox.ClientRectangle);
ImageFormat imageFormat = null;
var extension = Path.GetExtension(path);
switch (extension)
{
case ".bmp":
imageFormat = ImageFormat.Bmp;
break;
case ".png":
imageFormat = ImageFormat.Png;
break;
case ".jpeg":
case ".jpg":
imageFormat = ImageFormat.Jpeg;
break;
case ".gif":
imageFormat = ImageFormat.Gif;
break;
default:
throw new NotSupportedException("File extension is not supported");
}
bitmap.Save(path, imageFormat);
}
}
Upvotes: 1
Reputation: 23675
pictureBox1.Image.Save(filePath, ImageFormat.Jpeg);
Check this MSDN reference for further knowledge.
Upvotes: 4