C#C
C#3y ago
Binto86

❔ Bitmap created from graphics appears to be all black

I have some kind of drawing board in winforms. User draws into panel with graphics and than i want to save the image into file. relevant parts of code are (canvas is the name of the panel the user is drawing on):
Graphics graphics;
Pen pen;
Bitmap bmp;

public Form1()
{
  InitializeComponent();
  graphics = canvas.CreateGraphics();
  pen = new Pen(Color.Black, 35);
  bmp = new Bitmap(28, 28, graphics);
}

private void btnSave_Click(object sender, EventArgs e)
{
  var fileName = "digit.png";
  bmp.Save(fileName,ImageFormat.Png);
}

but the saved image is all black, any ideas why?
Was this page helpful?