qt关于rgb转int和int转rgb

时间:2022-10-29 18:54:45


#include <QCoreApplication>
#include <QDebug>

int rgbToInt(int p_r,int p_g,int p_b){
int rgbvalue = 0;
rgbvalue = p_r + p_g * 256 + p_b * 256 * 256;
return rgbvalue;
}
void intTorgb(int rgbvalue,int &p_r,int &p_g,int &p_b){
int r = rgbvalue & 0xff ;
int g = (rgbvalue & 0xff00) >> 8;
int b = (rgbvalue & 0xff0000) >> 16;

p_r = r;
p_g = g;
p_b = b;

}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
int value_r = 10;
int value_g = 20;
int value_b = 30;
int rgbvalue = rgbToInt(value_r,value_g,value_b);

int ret_value_r = 0;
int ret_value_g = 0;
int ret_value_b = 0;
qDebug()<<"rgbvalue"<<rgbvalue;
intTorgb(rgbvalue,ret_value_r,ret_value_g,ret_value_b);

qDebug()<<"r=="<<ret_value_r;
qDebug()<<"g=="<<ret_value_g;
qDebug()<<"b=="<<ret_value_b;

return a.exec();
}