// srcImage is a temporary pointer pointing to the original image
// targetImage is a temporary pointer used to point to the newly
// created empty surface
SDL_Surface *srcImage, *targetImage; SDL_Rect src, dest; srcImage = IMG_Load("image_with_alphachannel.png"); // convert the surface to correspond the current displaymode srcImage = SDL_DisplayFormatAlpha(srcImage); // the original image-surface is now lost in the memory, but this // is just an example... // create an empty surface. targetImage = SDL_CreateRGBSurface(SDL_HWSURFACE, srcImage->w, srcImage-h, srcImage->format->BitsPerPixel, srcImage->format->Rmask, srcImage->format->Gmask, srcImage->format->Bmask, srcImage->format->Amask); targetImage = SDL_DisplayFormatAlpha(targetImage); // original is lost again, but no prob.. src.x = j*frameWidth; src.y = i*frameHeight; src.w = frameWidth; src.h = frameHeight; dest.x = 0; dest.y = 0; // now we blit the original image to the newly created surface SDL_BlitSurface(srcImage, &src, targetImage, &dest); // now i created a new surface and blitted the original image into // it. at this point, the srcImage still has it's alpha channel, // but it has disappeared from targetImage. How to make that // previous transfer by not losing alpha channel?
So, how to transfer the original image into a new surface without
loosing the alpha channel? This code doesn’t make sense, originally the
new surface should be smaller and only part of the original image would be
blitted, but this code is to demonstrate the problem.