我正在使用 momentics IDE( native SDK)开发 BlackBerry 10 移动应用程序。
我想使用 C++ 更改容器的背景颜色。但不幸的是,与此有关[ link ], 你只能像下面这样定义它:
**Creating a color in C++:**
Color c1 = Color::fromRGBA(0.5f, 1.0f, 0.2f, 0.8f);
Color c2 = Color::fromARGB(0xff996633);
对于颜色,我想使用十六进制格式(“#xxxxxx”)。任何人都可以指导我吗?
最佳答案
Color c2 = Color::fromARGB(0xff996633);
使用十六进制 0x 是十六进制代码的 c++ 表示
。 ff是A成分,99是R,66是G,33是B
所以如果你想使用没有 alpha 的十六进制值 #000099
那就是
Color::fromARGB(0x00000099)
下面的代码会将一个字符串转换成一个十六进制值,不过你需要先把字符串中的#去掉,然后才能把这个字符串传给缓冲对象
#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;
}
关于c++ - 如何使用十六进制格式更改容器的背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22219397/