不久前,我询问了一个我遇到困难的精灵重新着色程序,并得到了一些很好的回应。基本上,我尝试编写一个程序,将给定文件夹中所有图片的像素从一种给定颜色重新着色为另一种颜色。
我相信我已经记下来了,但是,现在程序告诉我,我为我的颜色的红色分量指定了一个无效值。ValueError: Invalid red value specified.
即使它只是从 64 更改为 56。任何有关此事的帮助将不胜感激!
这是Python代码:
import os
import media
import sys
def recolour(old, new, folder):
old_list = old.split(' ')
new_list = new.split(' ')
folder_location = os.path.join('C:\\', 'Users', 'Owner', 'Spriting', folder)
for filename in os.listdir (folder):
current_file = media.load_picture(folder_location + '\\' + filename)
for pix in current_file:
if (media.get_red(pix) == int(old_list[0])) and \
(media.get_green(pix) == int(old_list[1])) and \
(media.get_blue(pix) == int(old_list[2])):
media.set_red(pix, new_list[0])
media.set_green(pix, new_list[1])
media.set_blue(pix, new_list[2])
media.save(pic)
如果名称== '主要':
while 1:
old = str(raw_input('Please insert the original RGB component, separated by a single space: '))
if old == 'quit':
sys.exit(0)
new = str(raw_input('Please insert the new RGB component, separated by a single space: '))
if new == 'quit':
sys.exit(0)
folder = str(raw_input('Please insert the name of the folder you wish to modify: '))
if folder == 'quit':
sys.exit(0)
else:
recolour(old, new, folder)