[求助]如何用C#实现插入光栅图像?
本人用的是VS 2005 C#,ObjectArx 2007开发环境,ObjectArx 下有个一个sample,ism文件夹下的,是VC++的,可以实现插入光栅图像,现在需要用C#实现,但是C++和C#使用的函数并不是一一对应的。
本人刚接触C#语言和CAD二次开发,一些语法还不熟悉,CAD中的DataBase、BlockTable等概念还不清楚。。。
程序运行的效果应该与cad菜单中的 插入->光栅图像参照 差不多,只不过程序插入图像的时候已经在代码中限定了插入位置和缩放比例,所以
不需要再指定插入点和缩放比例。
需要用到的类应该有RasterImage,RasterImageDef,其他的还不知道有没有。
希望各位不吝赐教
http://forums.autodesk.com/t5/NET/Crash-when-Creating-Raster-Image/m-p/1781005/highlight/true#M4933
这个贴子的代码可以运行吗?不是说Crash了吗?
我先看看吧!谢谢!
多谢了!
这个代码可以!
如下:
public void insertimage_new()
{
Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
using (Transaction t = tm.StartTransaction())
{ // open the dictionary
Autodesk.AutoCAD.DatabaseServices.ObjectId imgDictID = RasterImageDef.GetImageDictionary(db);
DBDictionary imgDict;
if (imgDictID.OldId == 0)
{
imgDictID = RasterImageDef.CreateImageDictionary(db);
}
// create the raster image definition
RasterImageDef rasterDef = new RasterImageDef();
// rasterDef.SourceFileName = mapURL;
rasterDef.SourceFileName = "D:\\atoll.jpg";
rasterDef.Load(); // test the image dictionary and the raster before going further
bool bTestLoad = rasterDef.IsLoaded;
Autodesk.AutoCAD.DatabaseServices.ObjectId TestImgDictID = RasterImageDef.GetImageDictionary(db);
imgDict = (DBDictionary)t.GetObject(imgDictID, OpenMode.ForWrite);
// add the raster definition to the dictionary iff it doesn't already exist
Autodesk.AutoCAD.DatabaseServices.ObjectId rasterDefID;
if (!imgDict.Contains("NewMap"))
{
rasterDefID = imgDict.SetAt("NewMap", rasterDef);
}
t.AddNewlyCreatedDBObject(rasterDef, true); /* test */
bool bTestImage = imgDict.Contains("NewMap"); // everything is good up to this point...
// now add the REAL raster image reference
RasterImage rasterRef = new RasterImage();
rasterRef.ImageDefId = rasterDef.ObjectId;
Autodesk.AutoCAD.DatabaseServices.ObjectId testRefID = rasterRef.ObjectId;
BlockTable bt = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead, false);
BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt, OpenMode.ForWrite, false);
btr.AppendEntity(rasterRef); tm.AddNewlyCreatedDBObject(rasterRef, true);
testRefID = rasterRef.ObjectId; t.Commit(); }
这段程序有问题,用程序中的“insertimage”命令插入图像之后,在参照管理器中该图像的状态显示为“未参照”,而且将图像拆离之后,屏幕上还留下一个图像的边界框;而用AutoCAD自身的功能插入图像,图像的状态显示为“已参照”,将图像拆离之后屏幕上的图像被彻底删除。这是怎么回事?
这个我刚看了,确实是这样的,但是不知道为什么,可能是某些参数没有设置,等待高手来解答 经过研究,在“ t.Commit();”前加入以下代码,就行了!复制代码 经过试验,确实如此。第一行代码没有也可以。复制代码 我先看看吧!谢谢!
请问例子的arx代码里如何控制图片的显示大小? 望指教 !
页:
[1]