Export image

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

Post Reply
Cyril
Posts: 4
Joined: 04 May 2009, 12:21

Export image

Post by Cyril » 02 Jul 2009, 18:54

hello

i have a second problem.
When i export a image a margin is applied around the bitmap.
example : Image

Is it possible do not have margin like this : Image

I'm using the code into your example :

Code: Select all

public void SaveAsImage()
        {
            if (_cadImage == null)
                return;
            if (saveImgDlg.ShowDialog() != DialogResult.OK)
                return;

            Zoom(1);

            DRect tmpRect = new DRect(0.0, 0.0, VisibleAreaSize.Width * ImageScale, VisibleAreaSize.Height * ImageScale);
            ImageFormat imgFrm = ImageFormat.Bmp;
            if (saveImgDlg.FileName == null)
                return;
            string tmp = saveImgDlg.FileName;
            if (tmp.ToUpper().IndexOf(ApplicationConstants.jpgextstr) != -1)
                imgFrm = ImageFormat.Jpeg;
            if (tmp.ToUpper().IndexOf(ApplicationConstants.bmpextstr) != -1)
                imgFrm = ImageFormat.Bmp;
            if (tmp.ToUpper().IndexOf(ApplicationConstants.tiffextstr) != -1)
                imgFrm = ImageFormat.Tiff;
            if (tmp.ToUpper().IndexOf(ApplicationConstants.gifextstr) != -1)
                imgFrm = ImageFormat.Gif;
            if (tmp.ToUpper().IndexOf(ApplicationConstants.emfextstr) != -1)
                imgFrm = ImageFormat.Emf;
            if (tmp.ToUpper().IndexOf(ApplicationConstants.pngextstr) != -1)
                imgFrm = ImageFormat.Png;
            if (tmp.ToUpper().IndexOf(ApplicationConstants.dxfextstr) != -1)
            {
                SaveAsDXF(saveImgDlg.FileName);
                return;
            }
            if (!this._clipRectangle.Enabled)
            {
                rasterSizeForm.Image = this._cadImage;
                rasterSizeForm.CurrentSize = tmpRect;
                rasterSizeForm.SaveFileName = saveImgDlg.FileName;
                if (rasterSizeForm.ShowDialog() == DialogResult.OK)
                    tmpRect = rasterSizeForm.SizeImage;
            }
            int tmpNumberOfPartsInCircle = this._cadImage.NumberOfPartsInCircle;
            this._cadImage.NumberOfPartsInCircle = CADConst.SetNumberOfPartsInCurve(tmpRect);
            if (this._clipRectangle.Enabled)
            {
                tmpRect = ImageDRect;
                if ((imgFrm == ImageFormat.Emf) || (imgFrm == ImageFormat.Wmf))
                    _cadImage.ExportToMetafile(saveImgDlg.FileName, tmpRect, this._clipRectangle.ClientRectangle);
                else
                    _cadImage.SaveToFile(saveImgDlg.FileName, imgFrm, tmpRect, this._clipRectangle.ClientRectangle, this.rasterSizeForm.ImagePixelFormat);
            }
            else
            {
                if ((imgFrm == ImageFormat.Emf) || (imgFrm == ImageFormat.Wmf))
                    _cadImage.ExportToMetafile(saveImgDlg.FileName, tmpRect);
                else
                    _cadImage.SaveToFile(saveImgDlg.FileName, imgFrm, tmpRect, this.rasterSizeForm.ImagePixelFormat);
            }
            this._cadImage.NumberOfPartsInCircle = tmpNumberOfPartsInCircle;
        }
Thanks for your help

Cyril

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

Re: Export image

Post by support » 03 Jul 2009, 17:33

Hello,
you can save image without the borders. To do this please modify your code sample by setting CADImage properties
BorderSize and IsWithoutMargins:

Code: Select all

            ...
            if (!this._clipRectangle.Enabled)
            {
                rasterSizeForm.Image = this._cadImage;
                rasterSizeForm.CurrentSize = tmpRect;
                rasterSizeForm.SaveFileName = saveImgDlg.FileName;
                if (rasterSizeForm.ShowDialog() == DialogResult.OK)
                    tmpRect = rasterSizeForm.SizeImage;
            }
            int tmpNumberOfPartsInCircle = this._cadImage.NumberOfPartsInCircle;
            this._cadImage.NumberOfPartsInCircle = CADConst.SetNumberOfPartsInCurve(tmpRect);

            this.cadImage.BorderSize = 0;                       
            this.cadImage.IsWithoutMargins = true;

            if (this._clipRectangle.Enabled)
            {
                tmpRect = ImageDRect;
            ...
Alexander.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply