Eto.Drawing error exporting PNG

Hi, I have a problem with exporting an image created with Eto.Drawing. The following code creates a completely black or transparent image, trying with all available PixelFormat values

// Material texture
var img = new Eto.Drawing.Bitmap(canvasSize, canvasSize, Eto.Drawing.PixelFormat.Format24bppRgb);

var g = new Eto.Drawing.Graphics(img);
g.FillRectangle(Eto.Drawing.Brushes.Gainsboro, 0, 0, canvasSize, canvasSize);

img.Save(filename, Eto.Drawing.ImageFormat.Png);

filename obviously ends with .png

Am I doing something wrong?
Thanks

1 Like

Hi @m.camillo,

You have to dispose of the Eto.Drawing.Graphics object before saving.

e.g.

// Material texture
var img = new Eto.Drawing.Bitmap(canvasSize, canvasSize, Eto.Drawing.PixelFormat.Format24bppRgb);

using (var g = new Eto.Drawing.Graphics(img))
{
  g.FillRectangle(Eto.Drawing.Brushes.Gainsboro, 0, 0, canvasSize, canvasSize);
}

img.Save(filename, Eto.Drawing.ImageFormat.Png);

Hope this helps!

Hi @curtisw,
thank you for the reply, that worked!
It would be nice to have these kind of information written somewhere in the documentation or in the Wiki, expecially when the behaviour is different from WMI/WPF/WinForm.

Thanks again!

Thanks for the feedback, I’ll add a note to the Graphics constructor when passing in a Bitmap that it needs to be disposed for the changes to be applied.

Cheers!
Curtis.

1 Like