有什么方法可以在 SDL2 中调整 PNG 图像的大小?

Is there any possible way to resize an PNG image in SDL2?

我正在使用 SDL2SDL_image.h。我当前的尝试是尝试将 .PNG 图像放入 SDL_Rect 中,这仅将我的图像隐藏在矩形区域中,因此不起作用。我正在按照 this tutorial 加载 .PNG 图像。我希望将图像拉伸到与屏幕相同的大小,即 640x480。这是我的尝试:

...
SDL_Rect surfWindRectBC;
SDL_Rect surfWindRectCI;

SDL_Surface * screenSurf = NULL;
SDL_Surface* current = SDL_CreateRGBSurface(0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0, 0, 0);
SDL_Surface * menu = IMG_Load(std::string(".\sprites\menu\background.png").c_str()); 
...
...
int main() {
    surfWindRectBC.w = SCREEN_WIDTH;
    surfWindRectBC.h = SCREEN_HEIGHT;
    surfWindRectCI.w = 32;
    surfWindRectCI.h = 32;
...
...
screenSurf = SDL_GetWindowSurface(window);
current = SDL_ConvertSurface(menu, screenSurf->format,0);
SDL_FreeSurface(menu);
...
...
while (game) {
                SDL_Event event;
                Uint8 input = 0;
                
                while (SDL_PollEvent(&event)) {...}
                SDL_BlitSurface(current, &surfWindRectBC, screenSurf, &surfWindRectCI);
                SDL_UpdateWindowSurface(window);
            }
...

查看文档也许您应该尝试使用 SDL_BlitScaled 而不是 SDL_BlitSurface