public void SaveFileAsBitmap(System.Windows.Forms.PictureBox picBoxCanvas, String filename) { using (var bitmap = new Bitmap(picBoxCanvas.Width, picBoxCanvas.Height)) { picBoxCanvas.DrawToBitmap(bitmap, picBoxCanvas.ClientRectangle); ImageFormat imageFormat = null; var extension = Path.GetExtension(filename); 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(String.Format("File extension {0} is not supported", extension)); } bitmap.Save(filename, imageFormat); } }
public void SaveFile(string file, int index, System.Windows.Forms.PictureBox contest) { if (index == 1) { using (FileStream fstream = new FileStream(file, FileMode.CreateNew)) { BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(fstream, Shapes); } } else { Bitmap bitmap = new Bitmap(contest.Width, contest.Height); contest.DrawToBitmap(bitmap, contest.Bounds); bitmap.Save(file); } }