Page 1 of 1

Load DWG Image and Save To EMF File

Posted: 22 Sep 2008, 06:07
by grazer
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.

Code: Select all

                    CADImportNetDemos.CADViewerDemo.MainForm form = new CADImportNetDemos.CADViewerDemo.MainForm();

                    form.openFileName = FileName;
                    form.imageFileName = imageFileName;

                    form.LoadFile(FileName);
                    form.SaveAsImage();
LoadFile code is unchanged.
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;
        }
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

Re: Load DWG Image and Save To EMF File

Posted: 22 Sep 2008, 10:44
by support
Hello Andrew,

Please try the following code:

Code: Select all

if(this.cadImage == null) 
{
	this.cadImage = new CADImage();
	this.cadImage.InitialNewImage();
	this.cadImage.UseDoubleBuffering = false;
}

cadImage.LoadFromFile(@"c:\Test.dxf");
DRect tmpRect = new DRect(0, 0, 1000,1000);
ImageFormat imgFrm = ImageFormat.Emf;

int tmpNumberOfPartsInCircle = this.cadImage.NumberOfPartsInCircle;
this.cadImage.NumberOfPartsInCircle = CADConst.SetNumberOfPartsInCurve(tmpRect);

cadImage.ExportToMetafile(@"c:\Test.emf", tmpRect);

this.cadImage.NumberOfPartsInCircle = tmpNumberOfPartsInCircle;
this.cadPictBox.Invalidate();
Sergey.