Reputation: 1389
Is there any way to insert one kind of image files such as png or jpg to a drawing, programmatically in c# by using Autodesk.Autocad.Interop
and Autodesk.Autocad.Interop.common
dlls?
I have tried AcadDocument.Database.ModelSpace.InsertBlock()
but it works just with dwg files and returns the following error for images :
"Invalid File Header."
Upvotes: 0
Views: 1263
Reputation: 3178
InsertBlock() is only for inserting block definitions. Use AddRaster() to import an image via AutoCAD Interop libraries:
var imgPath = @"C:\Users\Public\Pictures\Sample Pictures\Jellyfish.jpg";
var imgScale = 2.0;
var imgRot = (Math.PI / 180) * 90;
var imgPoint = new double[] {1, 1, 0};
doc.ModelSpace.AddRaster(imgPath, imgPoint, imgScale, imgRot);
Where 'doc' is the ActiveDocument of a running AutoCAD session.
Upvotes: 3