16进制字符窜表示的颜色转化为RGB格式

 经常使用TLex将字符窜转化为数字,不过一般都是10进制的字符窜的转化,TLex还有其他几种的转化方式,

见以下函数:

 

TInt Val(TUint8 &aVal, TRadix aRadix);

 

参数aRadix 可以指定为一下几个值:

EBinary

Convert number into binary character representation.

EOctal

Convert number into octal character representation.

EDecimal

Convert number into decimal character representation.

EHex

Convert number into hexadecimal character representation.

指定为EHex时就可以将16进制字符窜转化为数字。

 

利用这个方式就可以将16进制表示的颜色值转化为RGB的形式

如下:

TInt CGetPage::ChangeDesToRGB(const TDesC& aColorDes,TRgb & aRgbReturn)
{
 HBufC* color = HBufC::New(aColorDes.Length()+2);
 if (aColorDes.FindF(_L("#0x"))==0)
 {
  color->Des().Append(aColorDes.Mid(3));
 }
 else if (aColorDes.FindF(_L("#"))==0)
 {
  color->Des().Append(aColorDes.Mid(1));
 }
 else//有问题
 {
  delete color;
  return KErrNotFound;
 }

 TLex lex(*color);
 TUint result(0);
 if (lex.Val( result, EHex )==KErrNone)
 {
  TRgb newColor(result);
  //TInt aa = newColor.Red();
  //TInt bb = newColor.Green();
  //TInt cc = newColor.Blue();
  aRgbReturn.SetRed(newColor.Blue());//这里特别改动的,否则R、B顺序不对
  aRgbReturn.SetGreen(newColor.Green());
  aRgbReturn.SetBlue(newColor.Red());
  delete color;
  return KErrNone;
 }
 else
 {
  delete color;
  return KErrNotFound;
 }

}

 

用法:

    TRgb a;
    if (ChangeDesToRGB(_L("FF00FF"),a)==KErrNone)
    {
        a就是最后的颜色值
    }

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值