颜色进制转换

 c++:string 类型
740 /* String   RenderThemeAndroid::hex2rgb(WTF::String& color) {
741         if (color.substr(0, 1) == "#") color = color.substring(1);
742             color = color.toLowerCase();
743               b = new Array();
744               for (x = 0; x < 3; x++) {
745               b[0] = color.substr(x * 2, 2)
746               b[3] = "0123456789abcdef";
747               b[1] = b[0].substr(0, 1)
748               b[2] = b[0].substr(1, 1)
749               b[20 + x] = b[3].indexOf(b[1]) * 16 + b[3].indexOf(b[2])
750                }
751              return b[20] + "," + b[21] + "," + b[22];

752 }*/

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


/*int num_r[16]={0};      
786     int count_r=1;      
787     int result_r=0;
788     int length_r = 5;    
789     for (int i = length_r - 1;i>=0;i--)      
790     {      
791         if ((R[i]>='0') && (R[i]<='9'))      
792             num_r[i]=R[i]-48;//?路没SCII值为4793         else if ((R[i]>='a') && (R[i]<='f'))      
794             num_r[i]=R[i]-'a'+10;      
795         else if ((R[i]>='A') && (R[i]<='F'))      
796             num_r[i]=R[i]-'A'+10;      
797         else      
798             num_r[i]=0;    
799         result_r = result_r + num_r[i] * count_r;      
800         count_r = count_r * 16;//十?陆酶莽?掳私酶???鲁?801         XLOG("%d,result_r = %d**************************", __LINE__ ,result_r);
802     }      
803     nR = result_r;
804     XLOG("%d,nR = %d**************************", __LINE__ ,nR);

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/* if(color.GetLength() == 7)
905        {
906        CString cszR = "0x"+color.Mid(1,2);
907        CString cszG = "0x"+color.Mid(3,2);
908        CString cszB = "0x"+color.Mid(5,2);
909  
910        nR = strtol(cszR, NULL, 16);
911        nG = strtol(cszG, NULL, 16);
912        nB = strtol(cszB, NULL, 16);
913        }
914        else if(color.GetLength() == 6)
915        {
916        CString cszR = "0x"+color.Mid(0,2);
917        CString cszG = "0x"+color.Mid(2,2);
918        CString cszB = "0x"+color.Mid(4,2);
919  
920        nR = strtol(cszR, NULL, 16);
921        nG = strtol(cszG, NULL, 16);
922        nB = strtol(cszB, NULL, 16);
923        }
924        else {
925        nR = 0;
926        nG = 0;
927        nB = 0;
928        }*/

----------------------------------------------------------------------------------------------------------------------------------------------------------------

/*  float r;
946     float g;
947     float b;
948     if(color.at(0) == '#') {
949         color = color.erase(0, 1);
950     }
951     // ... and extract the rgb values.
952     std::istringstream(color.substr(0,2)) >> std::hex >> r;
953     std::istringstream(color.substr(2,2)) >> std::hex >> g;
954     std::istringstream(color.substr(4,2)) >> std::hex >> b;


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

webkit String 类型字符串转换


 String teststr="#0000FF";
XLOG("****teststr:%s",teststr.utf8().data());
String test1=teststr.substring(1,2);
String test2=teststr.substring(3,2);
String test3=teststr.substring(5,2);
XLOG("****test2:%s",test2.utf8().data());
bool ok;
//int value2=test2.toInt(&ok);
int value1=test1.toIntStrict(&ok,16);
int value2=test2.toIntStrict(&ok,16);
int value3=test3.toIntStrict(&ok,16);
XLOG("***ok:%d,value1:%d,value2:%d,value3:%d",ok,value1,value2,value3);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值