简体   繁体   English

有没有办法不用python中的matplotlib模块,通过输入R、G、B值0到255来生成RGB颜色?

[英]Is there a way to generate a RGB color by inputting R, G, and B values from 0 up to 255 without using the matplotlib module in python?

Is there a way to generate a color based on its RGB values rather than the following snippet?有没有办法根据其 RGB 值而不是以下代码片段生成颜色? (And preferably with a more compact module than matplotlib) (最好使用比 matplotlib 更紧凑的模块)

from matplotlib.pyplot import scatter, axis, show
R = float(input('Insert R value: '))
G = float(input('Insert G value: '))
B = float(input('Insert B value: '))

def RGB(R,G,B):
  r = R/255
  g = G/255
  b = B/255
  scatter([0],[0],color=(r, g, b), s=1e6)
  axis('off')
  print('R =', R,'\nG =', G,'\nB =', B)
  show()

RGB(R,G,B)

By inserting the values of R=50, G=100, and B=200 the code above will return the following window, which is basically a matplotlib scatter plot with an expanded dot:通过插入 R=50、G=100 和 B=200 的值,上面的代码将返回以下 window,这基本上是一个带有扩展点的 matplotlib 散点图 plot: 代码片段返回

Matplotlib is a huge module and when I try to generate an executable using Pyinstaller the size of the executable gets really big. Matplotlib 是一个巨大的模块,当我尝试使用 Pyinstaller 生成可执行文件时,可执行文件的大小变得非常大。 That's the reason why I'm asking.这就是我问的原因。

If I'm understanding your requirements properly, how about using pillow module:如果我正确理解您的要求,如何使用pillow模块:

from PIL import Image

r = input('Input R value: ')
g = input('Input G value: ')
b = input('Input B value: ')

im = Image.new('RGB', (500, 300), (r, g, b))
im.show()

which will display a rectangle window filled with specified color.这将显示一个矩形 window 填充指定的颜色。

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

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