Dhruv S.
Dhruv S.

Reputation: 23

Scale a screenshot of pygame screen

I'm trying to make a program that can guess a handwritten digit using the mnist dataset and pygame. When trying to scale a screenshot of my window I get an error. Any ideas? Here is the error in screenshot = pygame.transform.scale(screenshot,(28,28)):

TypeError: argument 1 must be pygame.Surface, not None

Code:

import pygame, sys
pygame.init()
size = x, y = 640, 480
screen = pygame.display.set_mode(size)

clock = pygame.time.Clock()
screenshot = pygame.image.save(screen, "screenshot.jpeg")
screenshot = pygame.transform.scale(screenshot,(28,28))

Upvotes: 1

Views: 76

Answers (1)

Valentino
Valentino

Reputation: 7361

You need to invert the order of your two last lines. First scale the screen: you'll get the scaled pygame.Surface (you won't see anything in your display since you are not blitting it). Then save the surface on the disk.

import pygame, sys
pygame.init()
size = x, y = 640, 480
screen = pygame.display.set_mode(size)

screenshot = pygame.transform.scale(screen,(28,28))
pygame.image.save(screenshot, "screenshot.jpeg")

This simple example will give you a black 28x28 image, since nothing is drawn on it before.

Upvotes: 2

Related Questions