Если вы работаете с модулем media
, то вы можете сделать это:
import media
def invert():
filename = media.choose_file() # opens a select file dialog
pic = media.load_picture(filename) # converts the picture file into a "picture" as recognized by the module.
for pixel in pic:
media.set_red(pixel, 255-media.get_red(pixel)) # the inverting algorithm as suggested by @Dingle
media.set_green(pixel, 255-media.get_green(pixel))
media.set_blue(pixel, 255-media.get_blue(pixel))
print 'Done!'
Процесс аналогичен, если вы используете модуль picture
, и выглядит следующим образом:
import picture
def invert():
filename = picture.pick_a_file() # opens a select file dialog
pic = picture.make_picture(filename) # converts the picture file into a "picture" as recognized by the module.
for pixel in picture.get_pixels(pic):
picture.set_red(pixel, 255-picture.get_red(pixel)) # the inverting algorithm as suggested by @Dingle
picture.set_green(pixel, 255-picture.get_green(pixel))
picture.set_blue(pixel, 255-picture.get_blue(pixel))
print 'Done!'
Надеюсь, это поможет