wuyue521_0
路人甲
路人甲
  • 注册日期2006-06-22
  • 发帖数47
  • QQ
  • 铜币272枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1540回复:3

请教:VB的一个问题,请帮忙看下,谢谢

楼主#
更多 发布于:2006-06-28 19:13
<P>在写给图层标注的时候,我试图用 commondialg.showcolor来选择标注的颜色</P>
<P>但是其返回的color是一个值,似乎是R、G、B的乘积</P>
<P>请问怎么转换为R、G、B的格式呢?</P>
喜欢0 评分0
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
1楼#
发布于:2006-06-29 10:44
<P>如何转换为 RGB 等效对象颜色值?</P>
<P><a href="http://support.microsoft.com/default.aspx?scid=kb%3Bzh-cn%3B140848" target="_blank" >http://support.microsoft.com/default.aspx?scid=kb%3Bzh-cn%3B140848</A></P>
<P>RGB函数颜色值</P>
<P>RGB三个字母,分别代表了Red、Green、Blue三种颜色,此三种色可称为“原色”,在计算机中,通过这三种色的不同组合,可得到各式各样的颜色。每种颜色有256种颜色值,取值范围是0~255,由此我们可以看出此法表示的颜色数目较上面两种方法大有增加,一共能表达256×256×256种颜色。</P>
<P>其中几种常见的颜色用RGB表示如下</P>
<P>黑色:RGB(0,0,0)</P>
<P>红色:RGB(255,0,0)</P>
<P>白色:RGB(255,255,255)</P>
<P>所以上面的小例又可写成:</P>
<P>me.BackColor=RGB(0,0,0)</P>十六进制数颜色值
<P>顾名思义,就是用十六进制数来表示颜色的方式。在VB窗体或控件的颜色调整中我们就用到过,那一堆以;H开头的东东即是它了。十六进制和RGB值是一一对应的,只要将RGB的各个值换算成两位的十六进制数,一个十六进制的颜色值就出现了。例如上面的黑色的十六进制值为;H0,红色的为;HFF0000,白色的当然就是:;HFFFFFF了。</P>
<P>所以上面的小例又可写成:</P>
<P>me.BackColor=;H0</P>
GIS麦田守望者,期待与您交流。
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
2楼#
发布于:2006-06-29 10:44
Dec2RGB 函数代码<BR>***********************************************************************<BR>*<BR>* Dec2RGB function: returns separate RGB values from object color value<BR>*<BR>* Usage:<BR>*         RGB = Dec2RGB(<Decimal Color>) ;; such as _SCREEN.BACKCOLOR<BR>*          ? RGB = "192, 192, 192"       ;; color is light gray if true<BR>*<BR>* FUNCTION dec2rgb<BR>LPARAMETERS tnDec<BR>IF tnDec < 0<BR>     WAIT WINDOW 'Must be a positive value'<BR>     RETURN ""<BR>ENDIF<BR>lTalk=IIF(SET('TALK')='ON',.T.,.F.)<BR>SET TALK OFF * Determine the hexadecimal equivalent of the decimal parameter passed<BR>lcHex = ""<BR>lnFactor = 24          ;; set up factor value one exponent greater than<BR>used FOR lnPos = 6 TO 1 STEP -1<BR>     lnFactor = lnFactor - 4     ;; decrement factorial<BR>     lnExp = 2 ^ lnFactor        ;; extrapolate next least power of two<BR>     FOR lnOrd = 15 TO 1 STEP -1<BR>          IF tnDec < lnExp            ;; no value greater than current one,<BR>               lcHex = lcHex + "0"    ;; so store a zero in this position<BR>               EXIT                   ;; go back for the next value<BR>          ENDIF<BR>          IF tnDec >= lnExp * lnOrd  ;; is value greater than or equal to?<BR>               * find the matching hex value from its ordinal position<BR>               lcHex = lcHex + SUBSTR('123456789ABCDEF', lnOrd, 1)<BR>               EXIT<BR>          ENDIF<BR>     ENDFOR<BR>     tnDec = tnDec % lnExp     ;; leave remainder of exponential division<BR>ENDFOR * reverse the order of the individual color indicators<BR>lcHex = RIGHT(lcHex, 2) + SUBSTR(lcHex, 3, 2) + LEFT(lcHex, 2) * convert the pairs into decimal values<BR>lnPick = 2          ;; offset to determine which pair to convert<BR>lcRGB = ["]     ;; start of string delineator * parse each color indicator and convert to decimal<BR>FOR lnColor = 1 TO 3<BR>     lcHue = SUBSTR(lcHex, (lnPick * lnColor) - 1, 2) ;; pull out color<BR>     lnMSB = ASC(LEFT(lcHue, 1))     ;; "Most Significant Bit"<BR>     lnLSB = ASC(RIGHT(lcHue, 1))     ;; "Least Significant Bit"      * subtract appropriate value from each to get decimal equivalent<BR>     lnMSB = lnMSB - IIF(lnMSB > 57, 55, 48)<BR>     lnLSB = lnLSB - IIF(lnLSB > 57, 55, 48)      * then add decimals together<BR>     lcRGB = lcRGB + TRANSFORM( lnMSB * 16 + lnLSB, '999') + ", "<BR>ENDFOR<BR>lcRGB = LEFT(lcRGB, LEN(lcRGB) - 2) + ["]  ;; replace last comma with quote<BR>RETURN lcRGB<BR>    
GIS麦田守望者,期待与您交流。
举报 回复(0) 喜欢(0)     评分
wuyue521_0
路人甲
路人甲
  • 注册日期2006-06-22
  • 发帖数47
  • QQ
  • 铜币272枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2006-06-29 12:33
非常感谢gis
举报 回复(0) 喜欢(0)     评分
游客

返回顶部