pygame结合pillow滤镜对图像进行淡入淡出显示.py _pygame显示pillow美女

pygame结合pillow滤镜对图像进行淡入淡出显示.py _pygame显示pillow美女

附:林素婉300.jpg (化名)

以下是部分代码预览:

"""pygame结合pillow滤镜对图像进行淡入淡出显示.py
本程序用pillow的增强器对图形进行处理,然后用pygame显示出来"""

import pygame
from pygame.locals import *
from PIL import Image,ImageEnhance


pygame.init()
w,h = 300,300
screen = pygame.display.set_mode((w,h))
pygame.display.set_caption("慢慢显示出来的美女,淡入淡出的图形编程技巧_PIL与pygame显示图形_作者:李兴球")

class Picture():
    def __init__(self,filepath):
        self.im  = Image.open(filepath)
        self.mode = self.im.mode
        self.size = self.im.size
        self.constract_enhancer = ImageEnhance.Contrast(self.im)
        self.color_enhancer = ImageEnhance.Color(self.im)
        self.brightness_enhancer = ImageEnhance.Brightness(self.im)
        self.sharpness_enhancer = ImageEnhance.Sharpness(self.im)
    def contract(self,factor):
        """factor应该在0和1之间的浮点数"""
        self.im = self.constract_enhancer.enhance(factor)
    def color(self,factor):
        """factor在0.0和1.0之间"""
        self.im = self.color_enhancer.enhance(factor)
    def brightness(self,factor):
        """factor在0.0和1.0之间"""
        self.im = self.brightness_enhancer.enhance(factor)
    def sharpness(self,factor):
        """factor在1.0和2.0之间, 异常处理略,上同"""
        self.im = self.sharpness_enhancer.enhance(factor)
    def update(self):
        self.data  = self.im.tobytes()
        self.image = pygame.image.fromstring(self.data,self.size,self.mode)
        screen.blit(self.image,(0,0))
        pygame.display.update()
    
      
clock = pygame.time.Clock()

picture1  = Picture("林素婉300.jpg")   #请自己设置一张像素为300x300照片即可.
factor = 0.0

如需要下载完整源代码及素材,请

成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)

李兴球

李兴球的博客是Python创意编程原创博客