java对rgb取反_颜色取反 rgb COLORREF | 学步园

编码时遇到下面问题

背景颜色和前景颜色需要取反

COLORREF m_clr[5];

//背景颜色

m_listPD.SetItemData(nCount,m_clr[nUltraOrder]);

//字的颜色取反

m_listPD.SetItemColor(nCount,0xFFFFFF - m_clr[nUltraOrder]);

方法即是

0xFFFFFF - $oldcolor

转自

echo dechex(0xFFFFFF - $oldcolor);

把原文贴出来吧,不然可能不知道怎么来的。

You can invert a color by subtracting each of its red, green, and blue components from 255. In other words:

new_red   = 255 - old_red

new_green = 255 - old_green

new_blue  = 255 - old_blue

You can break a color into its components, use this technique to invert the components, and then use RGB to recombine them into the inverted color. However, there is a much simpler method.

If a color's components are given as R, G, and B, then the color is represented as:

R + 256 * G + 256 * 256 * B

Now consider the representation of inverse of this color with components 255 - R, 255 - G, and 255 - B:

(255 - R) + 256 * (255 - G) + 256 * 256 * (255 - B)

= (255 + 256 * 255 + 256 * 256 * 255) -

(R + 256 * G + 256 * 256 * B)

= &HFFFFFF - the_original_color

So a simpler method for calculating the inverse of a color is:

new_color = &HFFFFFF - old_color

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值