I'm trying to convert a DWG file to WMF file by following the great sample ViewerDemo code.
I have almost do the job but i have got an exception "Object reference not set to an instance of an object" on ExportToMetafile method.
I'm scratching my head on what i'm doing wrong but did find out so far.
Below my peace of code :
Code: Select all
string strFileName = string.Empty;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "dwg files (*.dwg)|*.dwg";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
strFileName = openFileDialog1.FileName;
}
if (strFileName.Equals(string.Empty))
return;
CADImage cadImage = null;
if (cadImage == null)
{
cadImage = new CADImage();
cadImage.InitialNewImage();
cadImage.UseDoubleBuffering = false;
}
cadImage.LoadFromFile(strFileName);
DRect tmpRect = new DRect(0, 0, 1000, 1000);
ImageFormat imgFrm = ImageFormat.Wmf;
cadImage.DefaultColor = Color.Black;
cadImage.DefaultColor = CADImport.CADConst.clNone;
cadImage.ExportToMetafile(@"c:\Test.wmf", tmpRect); // => Get the message : "Object reference not set to an instance of an object"
//cadImage.SaveToFile(@"c:\Test.wmf", ImageFormat.Wmf, tmpRect); => Works
So wondering what is the difference between SaveToFile and ExportToMetafile cause both are able to generate WMF file ?
One last question. How get the current resolution of the DWG file. Actually, i would like to genreate WMF file with the same resolution of DWG file.
Thanks in advance for your help,
Best regards,
Cedric