Saving Images ...

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

I have a Metafile that I would like to save as an image. So far, this seems
to work fine:

Metafile x = new Metafile(myFilename);
x.Save(jpgFilename, ImageFormat.Jpeg);

While I get the image fine, the background is black. For the life of me, I
can't figure out how to make the background white. Any ideas?

Somebody please make me feel stupid. Thanks.
 
Peter Duniho said:
Black is the color of default-initialized pixels (0 for all components).
You have two options: modify the metafile so that it explicitly fills a
white background behind itself, or draw the metafile into a Bitmap
instance you've cleared to white and save the Bitmap instead of the
metafile.

Pete

Thank you Pete. I'm up for either of those 2 options (probably prefer the
Bitmap), but I can't find any example code anywhere to get me started. How
would I draw the Metafile object into a Bitmap object that has been cleared
to a white background?

Thanks again.
 
Peter Duniho said:
See the Graphics and Bitmap classes. In particular, create your
destination Bitmap, call Graphics.FromImage(), then draw whatever you want
with that Graphics instance (see Graphics.Clear() and Graphics.DrawImage()
for inspiration).

Don't forget to dispose your IDisposables. :)

Pete

Thanks again Pete. I'll check it out.
 
Back
Top