Change image size before rendering

Hi, I have following code

import sys
import sdl2.ext
RESOURCES_astro = sdl2.ext.Resources(__file__, "resources/astro")
window = sdl2.ext.Window("Hello World!", size=(500, 500))
imageSun = factory.from_image(RESOURCES_astro.get_path("sun.png"))

I want to resize / scale down the image before rendering / displaying it on the screen. How do i get this done ?

You don’t. You “scale it down” as a part of rendering, by supplying a smaller destination rect to SDL_RenderCopy than the source rect, and let the GPU handle the scaling.

How do I do that ? I have multiple image files of different sizes, want them to to re-scaled to say 75x75 before display. A code snippet will help since am quite new to this…

Note : Am using sdl2 without a desktop environment installed, therefore direct from the CLI

Do you have to use PySDL2? Scaling when rendering using raw SDL2 (e.g. from C) is easy, but the Python wrapper might be getting in the way of what you want to do.

Edit: It looks as though the copy method in the sdl2.ext.renderer.Renderer class is what you need. That maps to SDL_RenderCopyEx() and allows you to specify a destination rectangle.

1 Like

Thanks, will give it a shot.

Wrt why ptsdl2, it was more to use python to avoid complexity of c vs any other reason.