Load DWG Image and Save To EMF File
Posted: 22 Sep 2008, 06:07
Hi,
I was trying to do the following, with slightly changed code to your CADViewerDemo.
The change is adding the imageFileName variable which is
used in SaveAsImage to specify the name of the image without any user interaction.
LoadFile code is unchanged.
Here is the SaveAsImage code.
Unfortunately, I cannot get this to work correctly. The created EMF is only 1K in size. Is there some requirement to load the cadImage into a PictureBox first before it is able to be saved as an image?
Regards
Andrew
I was trying to do the following, with slightly changed code to your CADViewerDemo.
The change is adding the imageFileName variable which is
used in SaveAsImage to specify the name of the image without any user interaction.
Code: Select all
CADImportNetDemos.CADViewerDemo.MainForm form = new CADImportNetDemos.CADViewerDemo.MainForm();
form.openFileName = FileName;
form.imageFileName = imageFileName;
form.LoadFile(FileName);
form.SaveAsImage();
Here is the SaveAsImage code.
Code: Select all
public void SaveAsImage()
{
if (cadImage == null)
return;
this.cadImage.DefaultColor = Color.Black;
this.cadImage.DefaultColor = CADImport.CADConst.clNone;
DRect tmpRect = new DRect(0, 0, 1000,1000);
ImageFormat imgFrm = ImageFormat.Emf;
int tmpNumberOfPartsInCircle = this.cadImage.NumberOfPartsInCircle;
this.cadImage.NumberOfPartsInCircle = CADConst.SetNumberOfPartsInCurve(tmpRect);
if ((imgFrm == ImageFormat.Emf) || (imgFrm == ImageFormat.Wmf))
cadImage.ExportToMetafile(imageFileName, tmpRect);
else
cadImage.SaveToFile(imageFileName, imgFrm, tmpRect, PixelFormat.Format24bppRgb);
this.cadImage.NumberOfPartsInCircle = tmpNumberOfPartsInCircle;
}
Regards
Andrew