Python-使用HTML十六进制颜色填充创建PNG图像
我有一个生成随机十六进制代码的脚本,我想从中生成一个图像,用生成的颜色作为图像的填充。我看了看派拉布,但没能得到我想要的结果。有人能帮我弄清楚怎么做吗?请参见创建图像文件 跟随 请参见以创建图像文件 跟随Python-使用HTML十六进制颜色填充创建PNG图像,python,html,colors,hex,fill,Python,Html,Colors,Hex,Fill,我有一个生成随机十六进制代码的脚本,我想从中生成一个图像,用生成的颜色作为图像的填充。我看了看派拉布,但没能得到我想要的结果。有人能帮我弄清楚怎么做吗?请参见创建图像文件 跟随 请参见以创建图像文件 跟随 如果您觉得这很有用,请向上投票: #Hex to RGB def hex_to_rgb(value): value = value.lstrip('#') lv = len(value) return tuple(int(value[i:i+lv//3], 16) fo
如果您觉得这很有用,请向上投票:
#Hex to RGB
def hex_to_rgb(value):
value = value.lstrip('#')
lv = len(value)
return tuple(int(value[i:i+lv//3], 16) for i in range(0, lv, lv//3))
print(hex_to_rgb("#0022ff"))
#https://www.codespeedy.com/create-random-hex-color-code-in-python/
import random
import cv2
def generate_random_hex():
random_number = random.randint(0,16777215)
hex_number = str(hex(random_number))
hex_number ='#'+ hex_number[2:]
print('A Random Hex Color Code is :',hex_number)
return hex_number
width1, height1 = 300, 300
random_hex_code=generate_random_hex()
random_rgb_code=hex_to_rgb(random_hex_code)
image = create_blank(width1, height1, rgb_color=random_rgb_code)
cv2.imwrite('random'+random_hex_code+'.jpg', image)
如果您觉得这很有用,请向上投票:
#Hex to RGB
def hex_to_rgb(value):
value = value.lstrip('#')
lv = len(value)
return tuple(int(value[i:i+lv//3], 16) for i in range(0, lv, lv//3))
print(hex_to_rgb("#0022ff"))
#https://www.codespeedy.com/create-random-hex-color-code-in-python/
import random
import cv2
def generate_random_hex():
random_number = random.randint(0,16777215)
hex_number = str(hex(random_number))
hex_number ='#'+ hex_number[2:]
print('A Random Hex Color Code is :',hex_number)
return hex_number
width1, height1 = 300, 300
random_hex_code=generate_random_hex()
random_rgb_code=hex_to_rgb(random_hex_code)
image = create_blank(width1, height1, rgb_color=random_rgb_code)
cv2.imwrite('random'+random_hex_code+'.jpg', image)
是什么阻止您生成rgb颜色。是什么阻止您生成rgb颜色。这似乎更多的是一个注释,而不是一个答案。提供一个允许OP解决其问题的图像库在我看来是一种帮助,但我添加了代码。这似乎更多的是一个注释,不是答案。在我看来,提供一个允许OP解决问题的图像库是一种帮助,但我添加了代码。