Rastor图像只显示图像路径

时间:2018-04-13 13:22:26

标签: c# autocad

我正在尝试将图像添加到CAD绘图中,但只是获得一个显示路径的矩形,并且没有显示图像。

我是否可以不将图像添加到Paper Space或仅添加到纸张空间的特定类型的图像(在我的情况下添加.jpg类型)。这是我的代码。

private void AddLogoImage(Transaction trans, BlockTableRecord titleRecord)
    { 
        // Define the name and image to use
        string imageName = "Comp Logo";
        string fileName = @"C:\Autodesk\Image\comp_logo.jpg";

        RasterImageDef imageDef;
        ObjectId imageDefId;

        // Get the image dictionary
        ObjectId imageDictId = RasterImageDef.GetImageDictionary(titleRecord.Database);

        // Check to see if the dictionary does not exist, it not then create it
        if (imageDictId.IsNull)
        {
            imageDictId = RasterImageDef.CreateImageDictionary(titleRecord.Database);
        }

        // Open the image dictionary
        DBDictionary imageDict = trans.GetObject(imageDictId, OpenMode.ForRead) as DBDictionary;

        // Check to see if the image definition already exists
        if (imageDict.Contains(imageName))
        {
            imageDefId = imageDict.GetAt(imageName);
            imageDef = trans.GetObject(imageDefId, OpenMode.ForWrite) as RasterImageDef;
        }
        else
        {
            // Create a raster image definition
            RasterImageDef newImageDef = new RasterImageDef();

            // Set the source for the image file
            newImageDef.SourceFileName = fileName;

            // Load the image into memory
            newImageDef.Load();

            // Add the image definition to the dictionary
            imageDict.UpgradeOpen();
            imageDefId = imageDict.SetAt(imageName, newImageDef);
            trans.AddNewlyCreatedDBObject(newImageDef, true);
            imageDef = newImageDef;
        }

        // Create the new image and assign it the image definition
        using (RasterImage acRaster = new RasterImage())
        {
            acRaster.ImageDefId = imageDefId;

            Vector3d width;
            Vector3d height;

            // Check to see if the measurement is set to English (Imperial) or Metric units
            if (titleRecord.Database.Measurement == MeasurementValue.English)
            {
                width = new Vector3d((imageDef.ResolutionMMPerPixel.X * acRaster.ImageWidth) / 25.4, 0, 0);
                height = new Vector3d(0, (imageDef.ResolutionMMPerPixel.Y * acRaster.ImageHeight) / 25.4, 0);
            }
            else
            {
                width = new Vector3d(imageDef.ResolutionMMPerPixel.X * acRaster.ImageWidth, 0, 0);
                height = new Vector3d(0, imageDef.ResolutionMMPerPixel.Y * acRaster.ImageHeight, 0);
            }

            // Define the position for the image 
            Point3d insPt = new Point3d(720, 129, 0.0);

            // Define and assign a coordinate system for the image's orientation
            CoordinateSystem3d coordinateSystem = new CoordinateSystem3d(insPt, width * 2, height * 2);
            acRaster.Orientation = coordinateSystem;

            // Set the rotation angle for the image
            acRaster.Rotation = 0;

            // Add the new object to the block table record and the transaction
            titleRecord.AppendEntity(acRaster);
            trans.AddNewlyCreatedDBObject(acRaster, true);

            // Connect the raster definition and image together so the definition
            // does not appear as "unreferenced" in the External References palette.
            RasterImage.EnableReactors(true);
            acRaster.AssociateRasterDef(imageDef);
            imageDef.Dispose();
        }
    }

我不应该使用Rastor图像,如果没有,还有其他选择吗?

从dwg文件中正确显示PDF,但更喜欢没有矩形边框。

2 个答案:

答案 0 :(得分:0)

要显示无边框,您可以将图像的颜色属性设置为rgb(255,255,255),假设它是您正在使用的白色背景

答案 1 :(得分:0)

免费的TrueView免费DWG查看器不显示图像。图像已成功创建并在完整版AutoDesk AutoCAD中可见