天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 78|回复: 0

使用ObjectARX插入图片

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
[code]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


链接器->输入->附加依赖项 添加 acISMobjXX.lib
初始化中 acrxLoadModule(_T("acISMui.arx"),false); //否则 pDict->setAt(szName, pImageDef, objID);  返回 eNoClassId[/code]

 

 

 

 

使用ObjectARX插入图片
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

GMT+8, 2024-11-1 10:28 , Processed in 0.123719 second(s), 27 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表