我正在使用openFrameworks ofxPango插件来渲染文本,其中包含以下代码:
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 :(得分:1)
我认为颜色值应该在0.0f和1.0f的范围内,其中:
以下是Cairo library中的一些简略示例,其中ofxPango呼吁:
color_white
1.0, 1.0, 1.0, 1.0
color_black
0.0, 0.0, 0.0, 1.0
color_transparent
0.0, 0.0, 0.0, 0.0
color_magenta
1.0, 0.0, 1.0, 1.0