【发布时间】:2012-11-26 04:11:22
【问题描述】:
假设我有一个SDL_Surface,它只是一张图片。
如果我想让SDL_Surface 拥有该图像的三个副本,一个在另一个之下怎么办?
我想出了这个功能,但它没有显示任何内容:
void ElementView::adjust()
{
int imageHeight = this->img->h;
int desiredHeight = 3*imageHeight;
int repetitions = desiredHeight / imageHeight ;
int remainder = desiredHeight % imageHeight ;
SDL_Surface* newSurf = SDL_CreateRGBSurface(img->flags, img->w, desiredHeight, 32, img->format->Rmask, img->format->Gmask, img->format->Bmask,img->format->Amask);
SDL_Rect rect;
memset(&rect, 0, sizeof(SDL_Rect));
rect.w = this->img->w;
rect.h = this->img->h;
for (int i = 0 ; i < repetitions ; i++)
{
rect.y = i*imageHeight;
SDL_BlitSurface(img,NULL,newSurf,&rect);
}
rect.y += remainder;
SDL_BlitSurface(this->img,NULL,newSurf,&rect);
if (newSurf != NULL) {
SDL_FreeSurface(this->img);
this->img = newSurf;
}
}
【问题讨论】:
-
有什么理由不能只对原始图像进行多次 blit 处理吗?
-
@Xymotech,我不应该触摸实际将表面绘制到屏幕上的代码。
-
我认为问题在于
img不够大,无法在其中保存 3 个自身的副本。看起来没有创建任意大小的新表面的好方法。为什么不能触摸实际绘图的代码? -
我尝试使用
SDL_CreateRGBSurface创建一个与img相同但具有所需高度的新表面,然后在其上进行blitting,但它显示的是一个空图像。