Search code examples
c#bitmapsavepicturebox

Saving all Drawn Objects into a Bitmap


I have a Canvass (PictureBox) and Shapes, Images or Text can be drawn on it as seen int he picture below. What I want to do now is to save them all into one BITMAP File. I have no idea so how do I start?

enter image description here

PS: I'm using different Graphics object to draw each.


Solution

  • Found a workaround, this will save the drawings in my pictureBox/Canvass.

    private void button2_Click(object sender, EventArgs e)
        {
            SaveFileDialog save = new SaveFileDialog();
    
                //Creates a filter fir saving the Project File
                save.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp); *.PNG|*.jpg; *.jpeg; *.gif; *.bmp; *.PNG";     
                save.DefaultExt = ".bmp";
                save.AddExtension = true;
    
                if (save.ShowDialog() == DialogResult.OK)
                {
                    using (var bmp = new Bitmap(pictureBox_Canvass.Width, pictureBox_Canvass.Height))
                    {
                        pictureBox_Canvass.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
                        bmp.Save(save.FileName);
                    }
                }
        }
    

    SAMPLE OUTPUT

    enter image description here