I made a paint program, and the drawing content (from System.Drawing) is drawn on the panel. I attempted this method to do a simple save for now, and I only get a blank image.
My bitmap has its property .RawData to 0. Don't know if that matters.
When I hide the screen, and show it again, the panel becomes blank.
On a side note, when I call the panel's pnlPaint.Refresh(), the panel goes blank. The drawing is lost. Is this a double buffer thing, like it's not retaining the values?
private bool Save()
{
Bitmap bmpDrawing;
Rectangle rectBounds;
try
{
// Create bitmap for paint storage
bmpDrawing = new Bitmap(pnlPaint.Width, pnlPaint.Height);
// Set the bounds of the bitmap
rectBounds = new Rectangle(0, 0, bmpDrawing.Width, bmpDrawing.Height);
// Move drawing to bitmap
pnlPaint.DrawToBitmap(bmpDrawing, rectBounds);
// Save the bitmap to file
bmpDrawing.Save("a.bmp", ImageFormat.Bmp);
}
catch (Exception e)
{
MessageBox.Show("Error on saving. Message: " + e.Message);
}
return true;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…