简体   繁体   中英

Working with autocad in c#

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."

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM