毫秒转换小时,分钟,秒,及颜色转换

CTimeSpan span = t2 - t1
int nIndex = (int)span.GetTotalSeconds //得出程序运行的开始t1 到t2 运行的时间段的毫秒数

CString str;
str.format(_T("%d:%02d:%02d"),nIdex / 3600,nIdex %3600/60,nIdex %3600%60);

十进制颜色值转换RGB

void ToRGB(int color)
{
	int rgb[3];
	memset(rgb,0,sizeof(a));
	int b = (color &0xff);
	int g = (color>>8)&0xff;
	int r = (color>>16)&0xff;
	rgb[0] = r;
	rgb[1] = g;
	rgb[2] = b;
}  

RGB转换十进制

int Rgb2int(int rr, int gg,int bb) 
{
	int color = ((rr << 16) | (gg << 8) | bb);
	return color;
}

RGB 计算公式:
颜色值 = (65536 * Blue) + (256 * Green) + (Red)

RGB值转换16进制

#include <sstream>
#include <string>
using namespace std;

std::string rgb2hex(int r, int g, int b, bool with_head)
{
	stringstream ss;
	if (with_head)
		ss << "#";
	ss << std::hex << (r << 16 | g << 8 | b);
	return ss.str();
}

int main()
{
	int r = 255;
	int g = 255;
	int b = 255;
	string ss = rgb2hex(r, g, b, true);
    return 0;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值