我正在使用 xPango 插件的 openFrameworks 使用以下代码呈现文本:
ofxPango* pango;
ofxPCContext* context;
ofxPCPangoLayout* layout;
ofImage text_image;
pango = new ofxPango();
context = pango->createContextWithSurface(width, height);
context->color4f(1,1,1, 0.0f);
context->paint();
layout = context->createPangoLayout();
layout->setText(text);
layout->setTextColor(186,34,29, 1.0f);
layout->setWidth(width);
layout->setJustify(true);
//context->paint();
ofxPCPangoFontDescription* fd = new ofxPCPangoFontDescription();
fd->createFromString(font);
layout->setFontDescription(*fd);
layout->show();
text_image.allocate(context->getSurface()->getWidth(), context->getSurface()->getHeight(), OF_IMAGE_COLOR_ALPHA);
text_image.setFromPixels(context->getSurface()->getPixels(), text_image.width, text_image.height, OF_IMAGE_COLOR_ALPHA, true);
我很难理解它是如何layout->setTextColor(r,g,b,a)
工作的。如果我运行:
- 0,0,0,1 - 文本应为黑色
- 255,0,0 - 文本应为红色
- 186,34,29,1 - 文本应该是红色时显示为非常浅的灰色(可能是白色)
- 186,34,0,1 - 文本是黄色的,虽然它应该是红色的
为什么这些颜色出现错误?