1
我問了一段關於我遇到困難的sprite recolouring程序,並得到了一些很好的迴應。基本上,我試圖編寫一個程序,將給定文件夾中的所有圖片的像素從一種給定顏色重新着色到另一種顏色。media.set_xx ValueError
我相信我已經記下了,但現在程序告訴我,我的顏色的紅色部分指定了無效值。 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)