简体   繁体   English

调整图片大小SDL / c ++

[英]Resize image SDL/c++

I have an image, I want to scale it down so that it's not its original size. 我有一张图片,我想按比例缩小它,而不是原来的尺寸。

SDL_Rect bulletRect;
bulletRect.x = 10;
bulletRect.y = 10;
bulletRect.w = 10;
bulletRect.h = 10;

SDL_Surface *bullet = IMG_Load("/Users/tonymichaelsen/Documents/documents/Xcode-projects/c++/c++/bullet.png");
Uint32 colorKeyBullet = SDL_MapRGB(bullet->format, 255, 255, 255);
SDL_SetColorKey(bullet, SDL_SRCCOLORKEY, colorKeyBullet);

Blitted: 盲区:

if (drawBullet) //bool set to true in key event
{
    SDL_BlitSurface(bullet, NULL, screen, &bulletRect);
}
SDL_Flip(screen);

The only thing that changes is when I'm changing the x,y values of the bullet (image). 唯一更改的是当我更改项目符号(图像)的x,y值时。 When I'm changing the w,h it doesn't change and the color key has no effect. 当我更改w,h时,它不变,并且颜色键无效。
Whats wrong? 怎么了?

SDL_BlitSurface doesn't perform scaling, it requires that the destination size be equal to the source size. SDL_BlitSurface不执行缩放,它要求目标大小等于源大小。

You probably want to look into the SDL-OpenGL integration, which will allow you to use the texturing functionality of your video card for rescaling sprites. 您可能需要研究SDL-OpenGL集成,这将使您可以使用视频卡的纹理处理功能来调整Sprite的大小。

Instead of NULL you could pass it a new rect with the size you need. 可以使用所需大小的新rect代替NULL。 SDL_BlitSurface(bullet, NULL, screen, &bulletRect); SDL_BlitSurface(bullet,NULL,screen,&bulletRect);

int SDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect); int SDL_BlitSurface(SDL_Surface * src,SDL_Rect * srcrect,SDL_Surface * dst,SDL_Rect * dstrect);

"The width and height in srcrect determine the size of the copied rectangle. Only the position is used in the dstrect (the width and height are ignored)." “ srcrect中的宽度和高度确定复制的矩形的大小。dstrect中仅使用位置(宽度和高度被忽略)。”

Here it explains how it works: 这里说明了它是如何工作的:

http://www.libsdl.org/docs/html/sdlblitsurface.html http://www.libsdl.org/docs/html/sdlblitsurface.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM