ValueError: Only 24-bit or 32-bit surfaces can be smoothly scaled

Issue #188 wontfix
Anonymous created an issue

Hello, I'm trying to resize a font, but I got the following error : ValueError: Only 24-bit or 32-bit surfaces can be smoothly scaled Here's a little script to reproduce

import pygame
pygame.font.init()
font = pygame.font.Font(None, 12)
text = font.render("Your text here", 1, (255, 255, 255), (0, 0 , 0))
pygame.transform.smoothscale(text, (320, 120))

But if I replace

text = font.render("Your text here", 1, (255, 255, 255), (0, 0 , 0))

by

text = font.render("Your text here", 1, (255, 255, 255))

it works

Comments (5)

  1. Jason Marshall

    The arguments that are passed to the render method determine which function in SDL_ttf will be called. See SDL_ttf's documentation at http://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html and pygame's font_render function in src/font.c. The Solid and Shaded functions return 8-bit surfaces; the Blended functions return 32-bit surfaces.

    When you pass an argument to the background parameter, you will get back an 8-bit surface, which cannot be smoothscaled. When you do not pass an argument to the background parameter, you will get an 32-bit surface back. This is not really a bug, but it could be explained better in the pygame documentation.

    (Remember that there is a convert method for surfaces to convert 8-bit surfaces to 24-bit or 32-bit surfaces.)

  2. Log in to comment