【发布时间】:2021-01-26 18:13:03
【问题描述】:
我有这个代码:
import pygame, sys
pygame.init()
screen = pygame.display.set_mode([640,480])
screen.fill([100,100,100])
pygame.display.flip()
image = pygame.image.load("tree.png").convert_alpha()
surf = pygame.Surface([1024,1024])
for y in range(0,1024):
for x in range(0,1024):
surf.set_at((x,y), image.get_at((x,y)))
if x == 0 and y == 0:
print image.get_at((x,y))
print surf.get_at((x,y))
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.fill([100,100,100])
screen.blit(surf, [0,0])
pygame.display.flip()
pygame.quit()
它的作用是打开图像,然后将其复制到与原始图像(图像)不同的表面(冲浪)。 tree.png 部分是透明的,特别是在 x:0,y:0 处。当我在复制时,如果 x 为 0,y 为 0,那么我将打印出原始图像的颜色值和新表面的颜色值。但问题是,每当我复制表面时,alpha 总是更改为 255,使其成为不透明的图像。我认为使用 convert_alpha 会保存正确的 alpha 值(它确实适用于原始图像,而不是新表面)。有解决办法吗?
【问题讨论】:
标签: python pygame transparency pygame-surface