We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Export block to image

  Hi, I need to get a preview for each block. I managed to get image for every block. But the block is not in the center of the image. How to place each block in the center of image? And Hoe to fit block to image?

private void BlocksToImages()
string FILE_PATH = “ATT file 2.dwg”;
using (CadImage cadImage = (CadImage)Aspose.CAD.Image.Load(FILE_PATH))
List filteredEntities = new List();
foreach (var entity in cadImage.Entities)
if (entity is CadInsertObject)
CadInsertObject cadinsentity = (CadInsertObject)entity;
foreach (var entity in filteredEntities)
#region Generate Image
List oneEntiy = new List();
entity.ChildObjects.RemoveAll(x => x is CadAttrib);

            CadInsertObject cadobj = (CadInsertObject)entity;
            cadImage.Entities = oneEntiy.ToArray();

            BmpOptions bmpOptions = new BmpOptions();
            var dwfRasterizationOptions = new CadRasterizationOptions();
            bmpOptions.VectorRasterizationOptions = dwfRasterizationOptions;

            dwfRasterizationOptions.AutomaticLayoutsScaling = true;

            dwfRasterizationOptions.PageHeight = 400;
            dwfRasterizationOptions.PageWidth = 400;

            dwfRasterizationOptions.ScaleMethod = ScaleType.GrowToFit;

            Margins margins = new Margins();
            margins.Top = 5;
            margins.Left = 5;
            margins.Bottom = 5;
            margins.Right = 5;
            dwfRasterizationOptions.Margins = margins;
            string outImage = ((CadInsertObject)entity).Name.Replace("*", "") + ".bmp";

            cadImage.Save(outImage, bmpOptions);

ATT file 2.7z (38.4 KB)

Hi. Please, try adding this:

cadImage.Entities = oneEntiy.ToArray();
BmpOptions bmpOptions = new BmpOptions();

You make the operations that may change size of the drawing, UpdateSize will recalculate it.

It worked for me, thanks a lot.

1 Like