简体   繁体   English

reportlabs-python中的颜色代码

[英]color codes in reportlabs-python

I'm using reportlabs library of python to generate PDF reports. 我正在使用python的reportlabs库来生成PDF报告。 I need to understand which format of color code is needed to be passed. 我需要了解需要传递哪种颜色代码格式。

When I pass RGB code for light green (178,255,102), to the_canvas.setFillColorRGB(178,255,102) it gives me white. 当我将浅绿色(178,255,102)的RGB代码传递给the_canvas.setFillColorRGB(178,255,102)它给了我白色。 And if I provide universal RGB color code for any color, it still gives me the same white color. 如果我为任何颜色提供通用RGB颜色代码,它仍然给我相同的白色。

If I provide (25,51,0) , it gives me yellow, which is not RGB code for yellow. 如果我提供(25,51,0),它会给我黄色,这不是黄色的RGB代码。

How should I provide color codes to the reportlab in order to get the color I wanted. 我应该如何为reportlab提供颜色代码以获得我想要的颜色。 Which format is it using? 它使用的是哪种格式?

From what I can tell, using the 256 color space won't work. 据我所知,使用256色空间是行不通的。 The manual states that using 1 is 'all lights on full'. 该手册指出使用1是“所有灯都亮”。 So, to create 256,256,256 is actually done by using (1,1,1) . 因此,创建256,256,256实际上是通过使用(1,1,1) Thus, to get something in between, you'll have to use decimals. 因此,为了获得介于两者之间的东西,你将不得不使用小数。 For me, I wanted the RGB: (75,116,156) so I had to write: setFillColorRGB(0.29296875,0.453125,0.609375) . 对我来说,我想要RGB: (75,116,156)所以我不得不写: setFillColorRGB(0.29296875,0.453125,0.609375) That's the equivelant to: 75/256, 116/256, 156/256. 这是平等的: 75/256, 116/256, 156/256. A bit ridiculous IMO, but it came out perfect 有点荒谬的IMO,但它出来完美

In case anyone wants an example I did this. 如果有人想要一个例子,我就这样做了。

from reportlab.lib import colors
...
...
other code
...
...
customColor = colors.Color(red=(255.0/255),green=(204.0/255),blue=(153.0/255))

I used this color for a Table Style 我用这种颜色作为桌面风格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM