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,
Flipflop.

#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: %
s\n”,SDL_GetError());
exit(1);
}

sdlsurface=SDL_CreateRGBSurface(SDL_SWSURFACE,
SFCWIDTH,SFCHEIGHT,SFCBPP,0,0,0,0);
if (sdlsurface==NULL) {
printf(“CreateRGBSurface failed: %
s\n”, SDL_GetError());
}

Uint8 *pixeldata;
int i;
pixeldata=sdlsurface->pixels;

for (i=0;i<SFCWIDTH;i++) {
	*(pixeldata+i)=i;
}

SDL_SaveBMP(sdlsurface,"surface.bmp");
SDL_FreeSurface(sdlsurface);

}

This message was sent from the free private e-mail service by easy.com, 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()
http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fSetPalette.

Oh, and fix your clock.

-Christian