假設我有一個SDL_Surface
只是一個圖像。 如果我想讓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原始圖像? – Xymostech
@Xymostech,我不應該觸摸實際繪製表面到屏幕上的代碼。 –
我認爲問題在於'img'不夠大,無法在其中保存3個副本。看起來好像沒有一種創建具有任意大小的新曲面的好方法。爲什麼不能觸摸實際繪製的代碼? – Xymostech