Page 1 of 1

About convert dwg to png background and line color

Posted: 24 May 2017, 10:58
by pujols
Hi, I try convert dwg to png,
sample code:

Code: Select all

CADImage cadImage = CADImage.CreateImageByExtension(sourceFile);
cadImage.LoadFromFile(sourceFile);
DRect boundaryRectangle = new DRect(left, top, width, height);
Rectangle rect = new Rectangle(left, top, width, height);
cadImage.SaveToFile(outFileName, ImageFormat.Png, boundaryRectangle, rect);
the result show white background and black line as follows
img2.gif
img2.gif (101.12 KiB) Viewed 14535 times
dwg file in DWG TrueView show black background and white line as follows
img1.png
img1.png (252.28 KiB) Viewed 14535 times
I want to export png that all colors are same as show in DWG TrueView

I try add

Code: Select all

cadImage.BackgroundColor = Color.Black;
the result png background color is black, and line is still black.
how do I export png that all colors as same as dwg in DWG TrueView?
is CAD.NET auto change line color according to background color?

Re: About convert dwg to png background and line color

Posted: 25 May 2017, 17:03
by support
Hello,

CAD .NET doesn't change the objects color automatically, depending on the background color. You will need to adjust the default color for objects and the background color before saving to a file, as follows:

Code: Select all

cadImage.Painter.Settings.BackgroundColor = Color.Black.ToArgb();
cadImage.Painter.Settings.DefaultColor = Color.White.ToArgb();
Mikhail