读入一个bmp文件到autocad
www.dimcax.com
读入一个bmp文件到autocad
在一个老外的论坛上看到的,可以把一个bmp文件读到autocad中。
using system;
using system.collections.generic;
using system.linq;
using system.text;
using autodesk.autocad.runtime;
using autodesk.autocad.databaseservices;
using acap = autodesk.autocad.applicationservices;
using autodesk.autocad.geometry;
using system.drawing;
namespace classlibrary5
{
public class class1
{
[commandmethod("doit")]
public void test()
{
bitmap bitmap = new bitmap("c:\\hal9000.bmp");
database db = acap.application.documentmanager.mdiactivedocument.database;
using (transaction tr = db.transactionmanager.starttransaction())
{
blocktablerecord currentspace = tr.getobject
(db.currentspaceid, openmode.forwrite) as blocktablerecord;
for (int i = 0; i < bitmap.width; i++)
{
for (int j = 0; j < bitmap.height; j++)
{
dbpoint point = new dbpoint();
autodesk.autocad.colors.color color =
autodesk.autocad.colors.color.fromcolor(bitmap.getpixel(i, j));
point.color = color;
double z = (color.colorvalue.r + color.colorvalue.g + color.colorvalue.b) * 0.01;//change this
point.position = new point3d(i, j, z);
currentspace.appendentity(point);
tr.addnewlycreateddbobject(point, true);
}
}
tr.commit();
}
}
}
}
复制代码