Load DWG Image and Save To EMF File

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

Post Reply
grazer
Posts: 2
Joined: 19 Sep 2008, 06:16

Load DWG Image and Save To EMF File

Post by grazer » 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.

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

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Re: Load DWG Image and Save To EMF File

Post by support » 22 Sep 2008, 10:44

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.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply