如何改变使用十六进制格式的容器的背景颜色? [英] How To change the background color of a container using the Hex format?

查看:263
本文介绍了如何改变使用十六进制格式的容器的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用Momentics的IDE(原生SDK)黑莓10手机应用程序。

I'm developing a BlackBerry 10 mobile application using the momentics IDE (native SDK).

我想换用C ++容器的背景色。但不幸的是,与此[链接],你只能把它定义象下面这样:

I want to change the background color of a container using C++. But unfortunately, relating to this [link], you only can define it like below :

**Creating a color in C++:**
Color c1 = Color::fromRGBA(0.5f, 1.0f, 0.2f, 0.8f);
Color c2 = Color::fromARGB(0xff996633);

有关的颜色,我想用十六进制格式(#XXXXXX)。任何一个可以指导我一下吗?

For the color, I want to use the hex format ("#xxxxxx"). Any one can guide me on this ?

推荐答案

颜色C2 =颜色:: fromARGB(0xff996633); 使用十六进制 0X是C ++重新六角$ C $的C presentation 。 FF是一个组件,99是R,66是G和33是B

Color c2 = Color::fromARGB(0xff996633); is using hex the 0x is c++ representation of a hex code. ff is the A component, 99 is the R, 66 is the G and 33 is the B

所以,如果你想使用十六进制值#000099,不带alpha

So if you want to use the hex value #000099 with no alpha

那么这将是

Color::fromARGB(0x00000099)

以下code将字符串转换为十六进制值,则需要从字符串前手然而,删除#,然后可以将字符串传递到缓冲区对象

The following code will convert a string to a hex value, you will need to remove the # from the string before hand however, and then can pass the string into the buffer object

#include <iostream>
#include <sstream>

int main() { 

    std::string hexString("#ffffff");
    hexString.erase(hexString.begin());

    std::istringstream buffer(hexString);

    int value;

    buffer >> std::hex >> value;

    std::cout << std::hex << value;
    return 0;
}

这篇关于如何改变使用十六进制格式的容器的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆