我有一个pygame Surface,想要反转颜色.有没有比这更快更pythonic的方法?这很慢.
我知道从255中减去这个值不是"倒置颜色"的唯一定义,但它是我现在想要的.
我很惊讶pygame没有这样内置的东西!
谢谢你的帮助!
import pygame
def invertImg(img):
"""Inverts the colors of a pygame Screen"""
img.lock()
for x in range(img.get_width()):
for y in range(img.get_height()):
RGBA = img.get_at((x,y))
for i in range(3):
# Invert RGB, but not Alpha
RGBA[i] = 255 - RGBA[i]
img.set_at((x,y),RGBA)
img.unlock()
Run Code Online (Sandbox Code Playgroud)