【发布时间】:2017-04-22 16:48:55
【问题描述】:
我创建了一个类来操作图像,在 SRCALPHA 模式下有一个带有 pygame 表面的“表面”变量。如何设置额外的 alpha?。
我的代码是:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
import Image
import os
class ImageManipulation:
def loadPicture(self, imagePath):
# http://stackoverflow.com/questions/38665920/convert-pil-image-into-pygame-surface-image
# http://stackoverflow.com/questions/29662908/how-do-i-blit-an-image-to-a-surface-in-pygame-thats-the-same-size-as-a-rectangl
# http://stackoverflow.com/questions/28005641/how-to-add-a-background-image-into-pygame
image = Image.open(imagePath)
mode = image.mode
size = image.size
data = image.tobytes()
py_image = pygame.image.fromstring(data, size, mode)
self.width = py_image.get_rect()[2]
self.height = py_image.get_rect()[3]
surface = pygame.Surface((self.width, self.height), pygame.SRCALPHA, 32)
surface = surface.convert_alpha()
surface.blit(py_image, py_image.get_rect())
self.surface = surface
def setAlpha(self, opacity):
# howto made this?
self.set_alpha(opacity) 不起作用,当使用 transform() 函数混合图层时,会填充背景但不保留透明背景。
我已经加载了一个带有完全透明部分的按钮,需要为所有按钮设置 50% 的不透明度并保留背景透明度。示例:http://www.clipartbest.com/cliparts/eTM/y5L/eTMy5LzAc.png
【问题讨论】:
标签: python image-processing pygame pygame-surface