0

I am trying to turn a Image PIL to a Python Surface Image. I have this code from this question: Convert PIL Image into pygame surface image

from PIL import Image
import pygame

RandomImage = Image.open("random.png")
Mode1 = RandomImage.mode
Size1 = RandomImage.size
Data1 = RandomImage.tobytes()

py_RandomImage = pygame.image.fromstring(Data1, Size1, Mode1)

When I run this code, I get this error code:

ValueError: size needs to be (number width, number height)

Because I know numbers are needed there, I print my Image size numbers using the print function, and I get an output of (300, 100). Then. I put the number into the size area like this:

py_RandomImage = pygame.image.fromstring(Data1, (300, 100), Mode1)

Once I run the code, it still gives me the same error code, although I think I have already put in a number width and a number height with both lines of code.

Mark Rotteveel
  • 90,369
  • 161
  • 124
  • 175
goose
  • 1
  • 1

0 Answers0