使用ObjectARX插入图片
本帖最后由 csharp 于 2016-1-24 16:32 编辑Inside ObjectARX, there are two classes that we use to represent images, one is AcDbRasterImage and the other is AcDbRasterImageDef.
The AcDbRasterImage entity (image entity) works with theAcDbRasterImageDef object (image definition object) to implement rasterimages inside AutoCAD. The relationship between these two classes is much likethe relationship between an AutoCAD block definition object and a block insert entity.
The image entity is a drawable, selectable AutoCAD entity that places a rasterimage in model or ** space at a particular location and orientation. The image entity is linked to exactly one image definition object, to which it sends requests for image processing operations needed for displaying and plotting images. Because the image definition object manages all the image information he image entity is relatively small. Besides the image location and orientation, it contains a clip boundary, image fade, contrast and brightness parameters and other typical AcDbEntity properties like layer and color.
void InsertImage() { ACHAR* szName = _T(“MyTest”); ACHAR *fileName = _T(“C:\temp\newImage.jpeg”); AcGePoint3d org(10,10,0);
AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
AcDbRasterImageDef* pImageDef = new AcDbRasterImageDef(); Acad::ErrorStatus es = pImageDef->setSourceFileName(fileName); if(es != Acad::eOk) { delete pImageDef; return; } es = pImageDef->load(); ASSERT(es == Acad::eOk); AcDbObjectId dictID = AcDbRasterImageDef::imageDictionary(pDb);
if (dictID==AcDbObjectId::kNull) { es = AcDbRasterImageDef::createImageDictionary(pDb, dictID); if(es!= Acad::eOk) { delete pImageDef; ads_printf(_T(“nCould not create dictionaryn”)); return; } } AcDbDictionary* pDict = NULL; es = acdbOpenObject((AcDbObject*&)pDict, dictID, AcDb::kForWrite); if(es != Acad::eOk) { delete pImageDef; ads_printf(_T(“nCould not open dictionaryn”)); return; } BOOL bExist = pDict->has(szName); AcDbObjectId objID; if (!bExist) { pDict->setAt(szName, pImageDef, objID); } else { pDict->getAt(szName, (AcDbObject*&)pImageDef,AcDb::kForWrite); objID = pImageDef->objectId(); } // close Dictionary and Definition. pDict->close(); pImageDef->close();
AcDbRasterImage* pImage = new AcDbRasterImage; es = pImage->setImageDefId(objID); if (es != Acad::eOk) { delete pImage; return; }
AcDbObjectId modelId; modelId = acdbSymUtil()->blockModelSpaceId(pDb);
AcDbBlockTableRecord *pBTRecord; acdbOpenAcDbObject((AcDbObject*&)pBTRecord, modelId, AcDb::kForWrite);
es = pBTRecord->appendAcDbEntity(pImage);
pBTRecord->close(); AcDbObjectId entID = pImage->objectId(); AcGePoint3d TempPoint3d(3.0, 0, 0); AcGeVector3d LowerRightVector = TempPoint3d.asVector(); AcGePoint3d TempPoint3d2(0, 1.5, 0); AcGeVector3d OnPlaneVector = TempPoint3d2.asVector(); if (pImage->setOrientation(org, LowerRightVector, OnPlaneVector) !=Adesk::kTrue) { ads_printf(_T(“nSet Orientation failed.”)); pImage->close(); return; } pImage->setDisplayOpt(AcDbRasterImage::kShow, Adesk::kTrue); pImage->setDisplayOpt(AcDbRasterImage::kTransparent, Adesk::kTrue);
AcDbObjectPointer<AcDbRasterImageDefReactor> rasterImageDefReactor;
// new it rasterImageDefReactor.create();
// Set the entity to be its owner. es = rasterImageDefReactor->setOwnerId(pImage->objectId());
// if ok if (es == Acad::eOk) { AcDbObjectId defReactorId; // assign the object an objectId es = pDb->addAcDbObject(defReactorId, rasterImageDefReactor.object());
// if ok if (es == Acad::eOk) { // set the image reactor id pImage->setReactorId(defReactorId);
AcDbObjectPointer<AcDbRasterImageDef> rasterImagedef(pImage->imageDefId(), AcDb::kForWrite);
// if ok if (rasterImagedef.openStatus() == Acad::eOk) { rasterImagedef->addPersistentReactor(defReactorId); } } }
pImage->close(); }
via AutoCAD DevBlog-Virupaksha Aithal-August 07, 2012 at 08:29PM-http://adndevblog.typepad.com/au ... sing-objectarx.html
Class AcDbRasterImageDef is implemented in an ObjectARX application called acISMui.arx. Your application must link to the ObjectARX API library acISMobj18.lib to use any of the methods specific to this class.
Note that the AcDbObject methods on this class can be accessed without linking to acISMobj18.lib. Simply cast the object pointer (for example, as returned by acdbOpenObject) to class AcDbObject.
The library file is located at acISMobj18.lib
**** Hidden Message *****
xie xie lou zhu
get ! thank you!
xie xie lou zhu 是中文版就好看多了。
还有隐藏的,看看
谢谢楼主分享 支持 支持 支持 支持
看看!学习学习! 好贴,赞 一个!
good good
学习学习学习学习 这个我非常想学习
学习!!!!!!!!!!!!!!!!!!!!!! 回复可见,
查看精彩内容