gui.py 文件源码

python
阅读 48 收藏 0 点赞 0 评论 0

项目:photobooth 作者: LoiX07 项目源码 文件源码
def show_picture(self, filename, size=(0, 0), offset=(0, 0), flip=False, alpha=255):
        """
        Display of a picture
        """
        # Use window size if none given
        if size == (0, 0):
            size = self.size
        try:
            # Load image from file
            image = pygame.image.load(filename)
        except pygame.error as exc:
            raise GuiException("ERROR: Can't open image '" + filename + "': " +
                               exc.message)
        # Extract image size and determine scaling
        image_size = image.get_rect().size
        image_scale = min([min(a, b) / b for a, b in zip(size, image_size)])
        # New image size
        new_size = [int(a * image_scale) for a in image_size]
        # Update offset
        offset = tuple(a + int((b - c) / 2)
                       for a, b, c in zip(offset, size, new_size))
        # Apply scaling and display picture
        image = pygame.transform.scale(image, new_size).convert()
        image.set_alpha(alpha)
        # Create surface and blit the image to it
        surface = pygame.Surface(new_size)
        surface.blit(image, (0, 0))
        if flip:
            surface = pygame.transform.flip(surface, True, False)
        self.surface_list.append((surface, offset))
        return new_size
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号