gpt4 book ai didi

c++ - 如何在 C++、SDL 中更改图像大小

转载 作者:太空宇宙 更新时间:2023-11-04 11:24:25 25 4
gpt4 key购买 nike

如何在下面的代码中更改图像大小:

const int XHome = 10, YHome = 10;
const int WHome = 50, HHome = 50;
.
.
.

SDL_Surface* Image = SDL_LoadBMP(Address);

SDL_Rect destRect;

destRect.x = WHome * x;
destRect.y = HHome * y;
destRect.w = WHome;
destRect.h = HHome;

SDL_BlitSurface(Image, NULL, mainScreen, &destRect);

SDL_FreeSurface(Image);

当我将 Image 放入另一个 SDL_SurfacemainScreen 时,它大于 50*50。是否可以调整 Image 的大小?谢谢。


这是我将 WHome 和 HHome 设置为 50*50 时发生的情况。
由于我只有 5 个声誉,所以我无法发布图片。要查看图像,请单击 here .

但是当我将它们设置为原始图像大小时,这就是我所看到的:
here

最佳答案

根据 SDL_BlitSurface 文档:

Only the position is used in the dstrect (the width and height are ignored).

我强烈建议切换到 SDL 2,原因有很多(硬件加速是一个很大的原因);这个任务也会因纹理和 SDL_RenderCopy 而变得微不足道。 .如果您不知何故无法使用 SDL 1,您可以手动查看缩放表面,或使用像 SDL_gfx 这样的库。 ,它具有自定义 blit 函数。

关于c++ - 如何在 C++、SDL 中更改图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27173887/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com