So I have found example code on how I am supposed to add images to DXF in CAD .NET, but the image does not come up and it breaks the DXF.
Could you give a working example:
Here is my code:
double posX = 100;
double posY = 100;
string targetLayout = "Model";
CadRasterImageDef rasterImageDef = new CadRasterImageDef(@"D:\dummy.png", 498, 186);
rasterImageDef.ObjectHandle = "RefID";
rasterImageDef.SoftOwner = _cadImage.Layouts[targetLayout].BlockTableRecordHandle;
rasterImageDef.FileName = "dummy.png";
// inserts RasterImage inside dxf
CadRasterImage rasterImage = new CadRasterImage(
rasterImageDef,
new Cad3DPoint(posX, posY, 0),
new Cad3DPoint(0.5, 0, 0),
new Cad3DPoint(0, 0.5, 0)
);
rasterImage.ObjectHandle = "RefID-RasterImage";
rasterImage.SoftOwner = _cadImage.Layouts[targetLayout].BlockTableRecordHandle;
rasterImage.LayerName = "0";
rasterImage.ImageDefReference = "RefID";
rasterImage.DisplayFlags = 1;
rasterImage.InsertionPoint.X = posX;
rasterImage.InsertionPoint.Y = posY;
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();
but the above image does not appear in PDF not SVG export and the DXF save breaks the DXF, so now it is corrupt.
Basically I want to either replace an existing image or add a new one… it seams like it could be possible, but I have no idea how to do it.
Also it would be good to know if I could use a memory stream instead of a file path that would be good.