www.mxdraw.com
内容索引主面
前一个向上下一个
McDbRasterImage 类

光栅图片类,该类用于在CAD中显示光栅图形

C++
class McDbRasterImage : public McDbImage;

McDbRasterImage.h

例如:插入一个光栅图的例程代码

    void CDrawCommand::InsertImage()
    {
        CFileDialog openDlg(TRUE,_T("jpg"),NULL,
            OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
            _T("jpg(*.jpg) | *.jpg|bmp(*.bmp) | *.bmp|tif(*.tif) | *.tif||"),
            MxDraw::GetMxDrawWnd(MxDraw::GetCurOcxHandle() ) );

        CString sInitialDir = AfxGetApp()->GetProfileString(_T("MxDraw"),
            _T("InsertImager"),Mx::GetAppPath() );

        CString sFileName;
        openDlg.m_ofn.lpstrInitialDir= sInitialDir; //设置打开文件的缺省路径

        if(openDlg.DoModal() == IDOK)
        {
            sFileName = openDlg.GetPathName();
        }
        else
        {
            return;
        }

        int iFindPos = sFileName.ReverseFind('\');
        if(iFindPos >= 0)
        {
            CString sPath = sFileName.Left(iFindPos + 1);
            AfxGetApp()->WriteProfileString(_T("MxDraw"),_T("InsertImager"),sPath);
        }

        double dW = 10;
        double dH = 10;

        {
            // 得到相关图片消息
            Gdiplus::Image tmpImage(sFileName);
            if(tmpImage.GetLastStatus() != Gdiplus::Ok)
            {
                acutPrintf(_T("n 图片文件不能打开"));
                return;
            }
            dW =  tmpImage.GetWidth() / 10.0;
            dH =  tmpImage.GetHeight() / 10.0;
        }

        // 得到插入点。
        mds_point apt;
        int iRet = Mx::mcedGetPoint(NULL,_T("n 指定插入点:"),apt);
        if(iRet  != RTNORM)
            return;

        CString sName = sFileName;
        {
            sName = MxT::AnalyzeFileName(sFileName,FALSE);  
        }
        if(sName.IsEmpty() )
        {
            MXASSERT(0);
            return;
        }

        // 在字典对对象中创建图片定义对象。
        McDbDatabase* pDatabase = Mx::mcdbHostApplicationServices()->workingDatabase();
        McDbDictionary* pDict = NULL;
        pDatabase->getNamedObjectsDictionary(pDict,McDb::kForWrite);
        if(pDict == NULL)
            return;
        //


        McDbObjectId imageDictId;
        if(pDict->getAt(MCAD_IMAGE_DICT_NAME,imageDictId) != Mcad::eOk)
        {
            // 创建该字典.
            McDbDictionary* pImageDict = new McDbDictionary;
            if(pDict->setAt(MCAD_IMAGE_DICT_NAME,
                pImageDict,imageDictId) != Mcad::eOk)
            {
                MXASSERT(0);
                delete pImageDict;
                pImageDict = NULL;
            }
            else
            {
                pImageDict->close();
            }
        }

        pDict->close();

        McDbObjectId imageDefId;
        if(!imageDictId.isNull() )
        {
            McDbObjectPointer<McDbDictionary> spImageDict(imageDictId,McDb::kForWrite);
            if(spImageDict.openStatus() == Mcad::eOk)
            {
                if(spImageDict->getAt(sName,imageDefId) != Mcad::eOk)
                {
                    // 添加图象定义.
                    McDbRasterImageDef* pNewImageDef = new McDbRasterImageDef;
                    pNewImageDef->setSourceFileName(sFileName );

                    if(spImageDict->setAt(sName,
                        pNewImageDef,imageDefId) != Mcad::eOk)
                    {
                        MXASSERT(0);
                        delete pNewImageDef;
                        pNewImageDef = NULL;
                    }
                    else
                    {
                        pNewImageDef->close();
                    }
                }
            }
        }

        if(!imageDefId.isNull() )
        {
            // 创建Image实例。
            McDbRasterImage* pImage = new McDbRasterImage;
            McGeVector3d uCorner  = McGeVector3d::kXAxis * dW;
            McGeVector3d vOnPlane = McGeVector3d::kYAxis * dH;

            pImage->setOrientation( asPnt3d(apt),uCorner,vOnPlane);
            pImage->setImageDefId(imageDefId);

            MrxDbgUtils::addToCurrentSpaceAndClose(pImage);
        }
    }
Copyright (c) 2010. All rights reserved.
你认为该帮助怎么样? 发送反馈信息!