Yet another question about SDL_BlitSurface

I am trying to cut big PNG image (with alpha chanel) to pieces, like that:---------------------
SDL_Surface *CutFromBigImage(SDL_Surface *src, …) {
SDL_Rect rect;
SDL_Surface *dst;

rect.* = …; // fill it with coordinates
dst = SDL_CreateRGBSurface(src->flags, rect.w, rect.h,
src->format->BitsPerPixel,
src->format->Rmask, src->format->Gmask,
src->format->Bmask, src->format->Amask);
SDL_BlitSurface(src, &rect, dst, NULL);
return dst;
}

And it doesn’t work. I recieve an empty or complitely transparent small image.
If I replace SDL_BlitSurface() with manual loop like:

int x, y;
Uint8 r,g,b,a;
for(x=0; x<rect.w; x++) for(y=0; y<rect.h; y++) {
getPixel(src, x+rect.x, y+rect.y, &r, &g, &b, &a);
setPixel(dst, x, y, r, g, b, a);
}

I get a nice small sprite. So the question is what do I do wrong with
SDL_BlitSurface?

Hello !

The problem is that when you use SDL_BlitSurface with your
PNGs with AlphaChannel you actually use these AlphaChannels
during the blittings.

You need to use

int SDL_SetAlpha(SDL_Surface *surface, Uint32 flags, Uint8 alpha);

to turn off the Alpha Attributes.

Then you can use SDL_BlitSurface without problems.

CU

Torsten Giebl <wizard syntheticsw.com> writes:

The problem is that when you use SDL_BlitSurface with your
PNGs with AlphaChannel you actually use these AlphaChannels
during the blittings.
Weeeeelll… yes, that’s what I intended to do. Why have alpha channel and do
not use it?

You need to use
int SDL_SetAlpha(SDL_Surface *surface, Uint32 flags, Uint8 alpha);
to turn off the Alpha Attributes.
Then you can use SDL_BlitSurface without problems.
Excuse me, but can you explain a little more? On what surface should I disable
alpha chanel? On the source? But in that case source image would be blitted as
opaque, and result should become opaque also, won’t it?