且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 Pygame 裁剪图像?

更新时间:2023-11-10 21:19:34

cropped = pygame.Surface((80, 80))
cropped.blit(buttonStates, (0, 0), (30, 30, 80, 80))

一个表面上的 blit 方法将另一个表面粘贴"到它上面.blit 的第一个参数是源表面.第二个是要粘贴到的位置(在本例中为左上角).第三个(可选)参数是要粘贴的源图像的区域 - 在本例中为距顶部 30 像素和距左侧 30 像素的 80x80 正方形.

The blit method on a surface 'pastes' another surface on to it. The first argument to blit is the source surface. The second is the location to paste to (in this case, the top left corner). The third (optional) argument is the area of the source image to paste from -- in this case an 80x80 square 30px from the top and 30px from the left.