csharp 发表于 2016-1-24 16:31:14

使用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 *****                                 



kcyxw 发表于 2016-2-24 14:03:32

xie xie lou zhu

1149525671 发表于 2016-3-14 16:09:12

get ! thank you!

llq_78 发表于 2016-3-15 15:20:01

xie xie lou zhu

qq564837358 发表于 2016-4-19 14:42:57

是中文版就好看多了。

abc498091367 发表于 2016-4-22 20:18:25

还有隐藏的,看看

革天明 发表于 2016-4-22 21:35:32

谢谢楼主分享

用途 发表于 2016-4-30 20:41:19

支持 支持 支持 支持

gxgghw 发表于 2016-5-17 08:32:42

看看!学习学习!

cxjzxf 发表于 2016-5-17 09:24:16

好贴,赞 一个!

819534890 发表于 2016-5-17 19:20:13

good good

柴月二号 发表于 2016-5-19 23:10:32

学习学习学习学习

ARX2014 发表于 2016-6-27 09:45:21

这个我非常想学习

zjy2999 发表于 2016-6-30 10:59:34

学习!!!!!!!!!!!!!!!!!!!!!!

张和平 发表于 2016-9-29 22:10:54

回复可见,
查看精彩内容
页: [1] 2 3
查看完整版本: 使用ObjectARX插入图片