相关疑难解决方法(0)

范围值为伪彩色

我有一些浮点数(在Python中),范围从0到100.我想创建一个伪彩色图像,使颜色从绿色(对应于0)变为红色(100).这类似于matplotlib的pcolor.但是,我不想使用pcolor.

是否有像pseudocolorForValue(val,(minval,maxval))这样的函数,它返回对应于'val'的伪颜色值的RGB三元组?此外,此功能是否具有灵活性,可以选择是显示从绿色到红色还是从红色到绿色的颜色?

谢谢,尼克

python floating-point gradient colors

12
推荐指数
3
解决办法
6204
查看次数

PIL问题,OSError:无法打开资源

我正在尝试编写一个将文本放到图像上的程序,我正试图绕过PIL并遇到错误:OSError:无法打开资源.这是我的第一个python程序,如果错误很明显,请道歉.

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont


im = Image.open("example.jpg")
font_type = ImageFont.truetype("Arial.ttf", 18)
draw = ImageDraw.Draw(im)
draw.text(xy=(50, 50), text= "Text One", fill =(255,69,0), font = font_type)
im.show()
Run Code Online (Sandbox Code Playgroud)

我收到错误:

Traceback (most recent call last):
File "C:\Users\laurence.maskell\Desktop\attempt.py", line 7, in <module>
font_type = ImageFont.truetype("Arial.ttf", 18)
File "C:\Python34\lib\site-packages\PIL\ImageFont.py", line 259, in truetype
return FreeTypeFont(font, size, index, encoding, layout_engine)
File "C:\Python34\lib\site-packages\PIL\ImageFont.py", line 143, in __init__
self.font = core.getfont(font, size, index, encoding, 
layout_engine=layout_engine)
OSError: cannot open resource
Run Code Online (Sandbox Code Playgroud)

fonts image python-imaging-library python-3.x

10
推荐指数
5
解决办法
1万
查看次数

如何在 Pygame 中向矩形添加颜色渐变?

信息:我正在使用 pygame 绘制一个矩形,但希望将渐变添加到矩形中,使其看起来有阴影。

现在这是我的代码:

light_green = (0, 255, 0)
dark_green = (0, 100, 0)

pygame.draw.rect(screen, light_green, rect_dims) # Draws a rectangle without a gradient
Run Code Online (Sandbox Code Playgroud)


问题:我想在浅绿色和深绿色之间创建线性过渡,而不绘制一堆彼此堆叠的线条(因为这非常慢),那么有没有一种方法可以使用pygame?

python pygame gradient rect linear-gradients

7
推荐指数
1
解决办法
8193
查看次数