[MSCE C++]颜色获取问题

请问老师,

       如下模型中,我使用下面代码获取颜色。无法获取正确的显示颜色。displayParams.GetLineColorTBGR();可以获取正确颜色,但是对于正常模型,此方法获取到的却是错误的颜色。请问这个如果解决?

	virtual void _AnnounceElemDisplayParams(ElemDisplayParamsCR displayParams)
	{
		if(displayParams.IsFillColorTBGR()){
			color = displayParams.GetFillColorTBGR();
		}else if (displayParams.IsLineColorTBGR()) {
			color = displayParams.GetLineColorTBGR();
		}else {
			color = displayParams.GetLineColor();
		}
		//color = displayParams.GetLineColorTBGR();
		material_struct.transparency = displayParams.GetTransparency();
	}

3554.ttt.dgn

Parents
  • 请参考下面代码:

    SymbologyReporter symbReporter(eh);
        UInt32       clrId, clrIdx;
        bool         isTrueClr;
        WString      bookName, clrName;
        double       transparency;
        UInt index = 0;
        while (SUCCESS == symbReporter.GetColorID(clrId, index))
            index++;
        index--;
        symbReporter.GetTransparency(transparency, index);
        if (COLOR_BYLEVEL == clrId)
        {
            LevelId lvlID;
            symbReporter.GetLevelId(lvlID, index);
            LevelCacheR lvlCache = eh.GetDgnModelP()->GetLevelCacheR();
            LevelHandle lvlHandle = lvlCache.GetLevel(lvlID);
            clrId = lvlHandle.GetByLevelColor().GetColor();
        }
        DgnColorMapP pClrMap = DgnColorMap::GetForDisplay(eh.GetDgnModelP());
        IntColorDef  clrDef = pClrMap->GetColor(clrId);
        pClrMap->ExtractElementColorInfo(&clrDef, &clrIdx, &isTrueClr, &bookName, &clrName, clrId, *eh.GetDgnFileP());
    
     
    
        value["colors"].append((double)clrDef.m_rgb.red/255);
        value["colors"].append((double)clrDef.m_rgb.green/255);
        value["colors"].append((double)clrDef.m_rgb.blue/255);
        value["colors"].append(1.0 - transparency);

Reply
  • 请参考下面代码:

    SymbologyReporter symbReporter(eh);
        UInt32       clrId, clrIdx;
        bool         isTrueClr;
        WString      bookName, clrName;
        double       transparency;
        UInt index = 0;
        while (SUCCESS == symbReporter.GetColorID(clrId, index))
            index++;
        index--;
        symbReporter.GetTransparency(transparency, index);
        if (COLOR_BYLEVEL == clrId)
        {
            LevelId lvlID;
            symbReporter.GetLevelId(lvlID, index);
            LevelCacheR lvlCache = eh.GetDgnModelP()->GetLevelCacheR();
            LevelHandle lvlHandle = lvlCache.GetLevel(lvlID);
            clrId = lvlHandle.GetByLevelColor().GetColor();
        }
        DgnColorMapP pClrMap = DgnColorMap::GetForDisplay(eh.GetDgnModelP());
        IntColorDef  clrDef = pClrMap->GetColor(clrId);
        pClrMap->ExtractElementColorInfo(&clrDef, &clrIdx, &isTrueClr, &bookName, &clrName, clrId, *eh.GetDgnFileP());
    
     
    
        value["colors"].append((double)clrDef.m_rgb.red/255);
        value["colors"].append((double)clrDef.m_rgb.green/255);
        value["colors"].append((double)clrDef.m_rgb.blue/255);
        value["colors"].append(1.0 - transparency);

Children