【发布时间】:2017-05-10 04:15:17
【问题描述】:
有没有办法在 SDL 中调整窗口大小以适应加载的图像大小?当前,当您调整它的大小时,它会复制窗口后面的内容。 这是我的加载图像功能:
void userImage(SDL_Surface *surface, SDL_Window *window)
{
SDL_Surface *userLoadImage;
char FileLocation[200];
printf( "Please Enter the file location:\n" );
fgets(FileLocation, 200, stdin );
fflush(stdin);
FileLocation[strcspn(FileLocation,"\n")]=0;
char *const picturePath = FileLocation;
userLoadImage = IMG_Load( picturePath );
int width = userLoadImage->w; //Get the width
int height = userLoadImage ->h; //Get the height
printf("image width = %d\n", width);
printf("image width = %d\n", height);
SDL_BlitSurface(userLoadImage, NULL, surface, NULL);
SDL_SetWindowSize( window, width, height);
}
【问题讨论】:
-
如果你能指出它们会很棒,我还在学习(我的大部分代码是 C,但我需要一些 C++ 功能来让事情变得更容易)。谢谢
-
例如,将
printf更改为cout语句会添加一些简单的 C++ 功能。 (printf 在 C++ 和 C 中都是合法的) -
我将答案更改为更以 SDL 为中心的答案。很抱歉造成误解。
-
不用担心,但非常感谢 :)