Creating & saving a surface as a BMP file

Hello all,

I need to create a surface, plot some pixels onto
it, and save it out as a BMP file. When I try this
with the program below, and load the BMP file into
a paint program, all the pixels are black - it
seems to have no palette. With a hex editor I can
see that the values 0-255 are written to the file,
but I can’t see how to define the palette, if
that’s the right terminology.

I’m using 8bpp because I need to generate and save
around 1000 of these files, and they will each be
a little bigger than the physical screen.

Thanks for any help,

#include <stdio.h>
#include “SDL/SDL.h”

#define SFCWIDTH 256
#define SFCHEIGHT 1
#define SFCBPP 8

SDL_Surface *sdlsurface;

int main(int argc,char *argv[]) {
if(SDL_Init(SDL_INIT_VIDEO)<0) {
printf(“SDL initialization failed: %

if (sdlsurface==NULL) {
printf(“CreateRGBSurface failed: %
s\n”, SDL_GetError());

Uint8 *pixeldata;
int i;

for (i=0;i<SFCWIDTH;i++) {



This message was sent from the free private e-mail service by, the portal site owned by Stelios and the easyGroup. This email service is available to all members of the public to use for personal reasons only. Not all subscribers to this e-mail service are representatives of an easyGroup company.

ghjghj ghghj wrote:

I can’t see how to define the palette, if
that’s the right terminology.

Use SDL_SetPalette()

Oh, and fix your clock.