将图像作为背景添加到DXF
Contents
[
Hide
]如何在DXF中添加图像作为背景
问题: 如何在DXF中添加图像作为背景。
提示: 为背景图像创建一个CadRasterImageDef对象,为绘图插入背景创建一个CadRasterImage对象,向绘图实体添加一个CadRasterImage对象。
示例:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CadRasterImageDef rasterImageDef = new CadRasterImageDef("background.jpg", 0, 0); | |
rasterImageDef.ObjectHandle = "RefID"; | |
rasterImageDef.SoftOwner = cadImage.Layouts["Model"].BlockTableRecordHandle; | |
rasterImageDef.FileName = "background.jpg"; | |
// inserts RasterImage inside dxf | |
CadRasterImage rasterImage = new CadRasterImage( | |
rasterImageDef, | |
new Cad3DPoint(2700, 1300, 0), new Cad3DPoint(0.5, 0, 0), new Cad3DPoint(0, 0.5, 0)); | |
rasterImage.ObjectHandle = newObjectID; | |
rasterImage.SoftOwner = cadImage.Layouts["Model"].BlockTableRecordHandle; | |
rasterImage.LayerName = "0"; | |
rasterImage.ImageDefReference = "RefID"; | |
rasterImage.DisplayFlags = 1; | |
rasterImage.InsertionPoint.X = 2700; | |
rasterImage.InsertionPoint.Y = 1300; | |
rasterImage.UVector.X = 0.5; | |
rasterImage.VVector.Y = 0.5; | |
List<CadBaseEntity> entities = new List<CadBaseEntity>(cadImage.Entities); | |
entities.Insert( | |
0, | |
rasterImage); // add to the beginning to fill image with background, entities will be above | |
cadImage.Entities = entities.ToArray(); | |
List<CadBaseObject> objects = new List<CadBaseObject>(cadImage.Objects); | |
objects.Add(rasterImageDef); | |
cadImage.Objects = objects.ToArray(); | |
cadImage.Save(...) |