افزودن تصویر به عنوان پس‌زمینه در DWG

چگونه یک تصویر به عنوان پس‌زمینه در DWG اضافه کنیم

مسئله: چگونه یک تصویر به عنوان پس‌زمینه در DWG اضافه کنیم.

نکات: برای این کار، یک شیء CadRasterImageDef برای تصویر پس‌زمینه ایجاد کنید، یک شیء CadRasterImage برای قرار دادن پس‌زمینه برای نقشه‌کشی ایجاد کنید، یک شیء CadRasterImage را به اشیاء نقشه‌کشی اضافه کنید، یک شیء CadBaseObject ایجاد کنید و آن را به cadImage.Objects اضافه کنید، و همه چیز را از طریق CadBlockTableObject پردازش کنید.

مثال:

CadRasterImageDef rasterImageDef = new CadRasterImageDef("background.jpg", 0, 0);
rasterImageDef.ObjectHandle = "RefID";
rasterImageDef.SoftOwner = cadImage.Layouts["Model"].BlockTableRecordHandle;
rasterImageDef.FileName = "background.jpg";
// inserts RasterImage inside DWG, requires fixes for CadBlockEntity.cs
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.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);
// order doesn't matter but it is good idea to make is synchronized with below
// entities.Insert(0, rasterImage); // add to the beginning to fill image with background, entities will be above
entities.Add(rasterImage);
cadImage.Entities = entities.ToArray();
List<CadBaseObject> objects = new List<CadBaseObject>(cadImage.Objects);
objects.Add(rasterImageDef);
cadImage.Objects = objects.ToArray();
CadBlockTableObject blockTableObjectReference = null;
CadBlockEntity cadBlockEntity = null;
foreach (CadBlockTableObject tableObject in cadImage.BlocksTables)
{
if (string.Equals(tableObject.HardPointerToLayout, cadImage.Layouts["Model"].ObjectHandle))
{
blockTableObjectReference = tableObject;
break;
}
}
if (blockTableObjectReference != null && cadImage.BlockEntities.ContainsKey(blockTableObjectReference.BlockName))
{
cadBlockEntity = cadImage.BlockEntities[blockTableObjectReference.BlockName];
}
List<CadBaseEntity> blockEntities = new List<CadBaseEntity>(cadBlockEntity.Entities);
blockEntities.Insert(0, rasterImage); // add to the beginning to fill image with background, entities will be above
cadBlockEntity.Entities = blockEntities.ToArray();