---
name: "SDL_SetColorKey"
section: "3"
platform: "linux"
package: "libsdl1.2-dev"
version: "1.2.15+dfsg2-8"
release: "Debian 12 (Bookworm)"
platforms: ["linux"]
url: "https://new.carta.tech/SDL_SetColorKey"
---

# SDL\_SetColorKey(3)

Sets the color key (transparent pixel) in a blittable surface and RLE acceleration.

## NAME

SDL\_SetColorKey - Sets the color key (transparent pixel) in a blittable surface and RLE acceleration.

## SYNOPSIS

**#include "SDL.h"**

**int SDL\_SetColorKey**(**SDL\_Surface \*surface, Uint32 flag, Uint32 key**);

## DESCRIPTION

 Sets the color key (transparent pixel) in a blittable surface and enables or disables RLE blit acceleration.

RLE acceleration can substantially speed up blitting of images with large horizontal runs of transparent pixels (i.e., pixels that match the **key** value). The **key** must be of the same pixel format as the **surface**, **SDL\_MapRGB** is often useful for obtaining an acceptable value.

If **flag** is **SDL\_SRCCOLORKEY** then **key** is the transparent pixel value in the source image of a blit.

If **flag** is OR'd with **SDL\_RLEACCEL** then the surface will be draw using RLE acceleration when drawn with *SDL\_BlitSurface*. The surface will actually be encoded for RLE acceleration the first time *SDL\_BlitSurface* or *SDL\_DisplayFormat* is called on the surface.

If **flag** is 0, this function clears any current color key.

## RETURN VALUE

This function returns **0**, or **-1** if there was an error.

## SEE ALSO

**SDL\_BlitSurface**, **SDL\_DisplayFormat**, **SDL\_MapRGB**, **SDL\_SetAlpha**
