Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // this is how the graphical object of the pictureBox1 control is declared
- public static Graphics g;
- private void Form1_Load(object sender, EventArgs e)
- {
- g = pictureBox1.CreateGraphics();
- }
- // this is how I save what was drawn on g
- private Bitmap DrawControlToBitmap(Control control)
- {
- Bitmap bitmap = new Bitmap(control.Width, control.Height);
- Graphics graphics = Graphics.FromImage(bitmap);
- Rectangle rect = control.RectangleToScreen(control.ClientRectangle);
- graphics.CopyFromScreen(rect.Location, Point.Empty, control.Size);
- return bitmap;
- }
- private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Bitmap bitmap = DrawControlToBitmap(pictureBox1);
- SaveFileDialog dialog = new SaveFileDialog();
- dialog.Filter = "PNG File (*.png)|*.png|JPEG File (*.jpeg)|*.jpeg|ICON File (*.ico)|*.ico|BITMAP File (*.bmp)|*.bmp|ALL FILES (*.*)|*.*";
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- if (dialog.FilterIndex == 1)
- {
- bitmap.Save(dialog.FileName, System.Drawing.Imaging.ImageFormat.Png);
- }
- else if (dialog.FilterIndex == 2)
- {
- bitmap.Save(dialog.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
- }
- else if (dialog.FilterIndex == 3)
- {
- bitmap.Save(dialog.FileName, System.Drawing.Imaging.ImageFormat.Icon);
- }
- else if (dialog.FilterIndex == 4)
- {
- bitmap.Save(dialog.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
- }
- else if (dialog.FilterIndex == 5)
- {
- bitmap.Save(dialog.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement