[求助]如何用C#实现插入光栅图像?
<p>本人用的是VS 2005 C#,ObjectArx 2007开发环境,ObjectArx 下有个一个sample,ism文件夹下的,是VC++的,可以实现插入光栅图像,</p><p>现在需要用C#实现,但是C++和C#使用的函数并不是一一对应的。</p>
<p>本人刚接触C#语言和CAD二次开发,一些语法还不熟悉,CAD中的DataBase、BlockTable等概念还不清楚。。。</p>
<p> </p>
<p>程序运行的效果应该与cad菜单中的 插入->光栅图像参照 差不多,只不过程序插入图像的时候已经在代码中限定了插入位置和缩放比例,所以</p>
<p>不需要再指定插入点和缩放比例。</p>
<p> </p>
<p>需要用到的类应该有RasterImage,RasterImageDef,其他的还不知道有没有。</p>
<p> </p>
<p>希望各位不吝赐教</p> <p><font face="Verdana"><a href="http://forums.autodesk.com/t5/NET/Crash-when-Creating-Raster-Image/m-p/1781005/highlight/true#M4933">http://forums.autodesk.com/t5/NET/Crash-when-Creating-Raster-Image/m-p/1781005/highlight/true#M4933</a></font></p>
<p> </p>
[求助]如何用C#实现插入光栅图像?
<p>这个贴子的代码可以运行吗?不是说Crash了吗?</p><p>我先看看吧!谢谢!</p>
回复:(lzh741206)http://forums.autodesk.com/t5/N...
多谢了!这个代码可以!
如下:
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();
}
<p>这段程序有问题,用程序中的“insertimage”命令插入图像之后,在参照管理器中该图像的状态显示为“<font color="#ff0000">未参照</font>”,而且将图像拆离之后,屏幕上还留下一个图像的<font color="#ff0000">边界框</font>;而用AutoCAD自身的功能插入图像,图像的状态显示为“已参照”,将图像拆离之后屏幕上的图像被彻底删除。这是怎么回事?</p>
回复:(gyl)这段程序有问题,用程序中的“insertima...
这个我刚看了,确实是这样的,但是不知道为什么,可能是某些参数没有设置,等待高手来解答回复:(gyl)这段程序有问题,用程序中的“insertima...
经过研究,在“ t.Commit();”前加入以下代码,就行了! RasterImage.EnableReactors(true);rasterImg.AssociateRasterDef(rasterDef);
malasky发表于2010-7-20 9:36:00static/image/common/back.gif经过研究,在“ t.Commit();”前加入以下代码,就行了!以下内容为程序代码:RasterImage.EnableReactors(true); rasterImg.AssociateRasterDef(rasterDef);经过试验,确实如此。第一行代码没有也可以。帮助里解释的太简单了,许多方法和属性都没有讲到实质,让人摸不着头脑。
<p>我先看看吧!谢谢!</p> 请问例子的arx代码里如何控制图片的显示大小? 望指教 !
页:
[1]
2