| Article | 70002714 |
| Type | HowTo |
| Product | Engine |
| Date Added | 6/17/2025 12:00:00 AM |
| Fixed | 11.4.4 (6/17/2025 12:00:00 AM) |
| Submitted by | GecDeveloper |
Summary
I would like to export a drawing as a PNG image where the background of VDF is transparent. How can I do it?
Solution
You need to render the contents of the drawing you want to a bitmap then set the transparent color or colors and save it to disk, like:
private void button1_Click(object sender, EventArgs e)
{
doc.Open(@"C:\test\test.vdml"); // open a sample file.
doc.Redraw(true);
Bitmap bmp = new Bitmap(400,400); // set the image size
doc.ActiveLayOut.RenderToBitmap(bmp); // render it to the bitmap
Color backColor = doc.ActiveLayOut.BkColorEx;
if (doc.ActiveLayOut.BkColorEx == Color.Empty)
{
backColor = doc.Palette.Background;
} // get the color of the VDF Background
try
{
Bitmap myBitmap = bmp;
// Make backColor transparent for myBitmap.
myBitmap.MakeTransparent(backColor);
// OPTIONALLY, you may make any other color transparent
// myBitmap.MakeTransparent(MyRedColo);
// myBitmap.MakeTransparent(MyGreenColor);
// Save myBitmap to file.
myBitmap.Save(@"C:\test\test.png");
}
catch
{
//check
//must do something
}
}
