需要移动屏幕的一小部分区域

时间:2016-02-14 20:34:47

标签: python animation pygame

如何将曲面的一小部分转换为图像对象? 当文档谈论一个名为numpty的类时,我根本不是python专家吗?另一个叫做tostring和fromstring的函数,目前还不清楚。我认为from_rect()可以提供帮助,但对我来说也不是很明显。

我想知道做以下事情的最佳方法是什么: 我正在加载一张照片,然后再将其保存。但是想要将一个小的32x32区域从中间转换为精灵,然后将sprite重新插入,但是几个像素降低(没有透明度或任何花哨的东西)。如何将曲面的一小部分转换为图像对象?

DECLARE @tbl TABLE(CityName VARCHAR(100));
INSERT INTO @tbl VALUES ('xy'),('Long name'),('very long name'),('middle'),('extremely long name');

WITH MyCTE AS 
(
    SELECT MAX(LEN(CityName)) AS Longest
          ,MIN(LEN(CityName)) AS Shortest
    FROM @tbl
)
SELECT * 
FROM MyCTE
--You must think about the chance of more than one city matching the given length
CROSS APPLY(SELECT TOP 1 CityName FROM @tbl WHERE LEN(CityName)=Longest) AS LongestCity(LongName)
CROSS APPLY(SELECT TOP 1 CityName FROM @tbl WHERE LEN(CityName)=Shortest) AS ShortestCity(ShortName)

1 个答案:

答案 0 :(得分:0)

您正在寻找pygame.Surface.subsurface

keyboard = pygame.transform.scale(keyboard, size)
my_little_copy = keyboard.subsurface(Rect(500, 300, 32, 32)).copy()
screen.blit(keyboard, (0, 0))
screen.blit(my_little_copy, (500, 350))