Cadlib将带有图像的模型绘制到位图

时间:2019-10-09 12:54:26

标签: cad dxf

我正在使用Cadlib来读取DWGDXFPDF体系结构文件,其中一些文件包含图像,我创建了一个DXFModel想要将那些DXFImages添加到其中,然后导出到jpg,我总是得到白色图像。

 DxfModel dxfModel = new DxfModel();
        foreach(DxfImage image in cadMimages)
        {
            dxfModel.Images.Add(image.ImageDef);
            image.SetDefaultBoundaryVertices();
            dxfModel.Entities.Add(image);
        }
        GraphicsConfig graphicsConfig = new GraphicsConfig(false, ArgbColors.White)
        {
            FixedForegroundColor = ArgbColors.Black,
            CorrectColorForBackgroundColor = false,
            ApplyLineType = true,
            DisplayLineWeight = true,
            DrawImages =true,
            DrawImageFrame=true
        };

        var boundsCalculator = new BoundsCalculator();
        boundsCalculator.GetBounds(dxfModel);
        var bounds_ = boundsCalculator.Bounds;
        Size maxSize = new Size(4096, 4096);
        var width = maxSize.Width;
        var height = maxSize.Height;
        var point1 = new WW.Math.Point3D(0, height - 1, 0);
        var point2 = new WW.Math.Point3D(width - 1, 0, 0);
        var to2DTransform = DxfUtil.GetScaleTransform(bounds_.Corner1, bounds_.Corner2, point1, point2);
        var bitmap = ImageExporter.CreateAutoSizedBitmap(dxfModel, new GDIGraphics3D(graphicsConfig), SmoothingMode.AntiAlias, to2DTransform, maxSize);
        using (Stream stream = File.Create("d:/test.png"))
        {
            ImageExporter.EncodeImageToPng(bitmap, stream);
        }

0 个答案:

没有答案