pygame每像素精准透明度测试程序pygame.surfarray.pixels_alpha例子

"""
   pygame精准透明度测试程序pygame.surfarray.pixels_alpha例子
   
"""

__author__ = "李兴球"
__date__ = "2019/8/30"

import pygame

image = pygame.image.load('images/test.png')
screen = pygame.display.set_mode(image.get_size(),0,32)
image = image.convert_alpha()

alpha = pygame.surfarray.pixels_alpha(image)
alpha[:] = 100    # 直接改变每个像素的透明度为100

print(alpha)
del alpha

print('每个像素的透明度已被改变!',image.get_at((10,10)))
screen.blit(image,(0,0))
pygame.display.flip()

# 以下为按任意键关闭pygame窗口
while not any(pygame.key.get_pressed()):
    pygame.event.pump()
    pygame.time.delay(100)
pygame.quit()