Python Pygame Surface.set_at是否将alpha设置为255?

Python Pygame Surface.set_at是否将alpha设置为255?,python,pygame,transparency,pygame-surface,Python,Pygame,Transparency,Pygame Surface,我有以下代码: 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 ran

我有以下代码:

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值(对原始图像,而不是新曲面,确实如此)。是否对此进行了修复?

问题不是由
图像
表面引起的,而是由
冲浪
表面引起的。从PNG文件创建的曲面具有逐像素alpha格式。但是,必须通过指定
SRCALPHA
标志,以每像素alpha格式创建目标:

surf=pygame.Surface([10241024])

surf=pygame.Surface([10241024],pygame.SRCALPHA)
或者,您可以使用以下方法更改曲面的像素格式,包括每像素Alpha:

surf=pygame.Surface([10241024]).convert_alpha()