How can I crop an image with Pygame?

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

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 80×80 square 30px from the top and 30px from the left.

Leave a Comment