Subj : Re: Screen Capture function To : borland.public.cpp.borlandcpp From : Jeff Baker Date : Thu Jul 08 2004 04:27 pm Okay, the problem was in the data field of the bmp file. There are 2 pixels represented in each byte. So in order to fix the problem I shifted the result of the first call to getpixel, incremented the horizontal count and then added that to another call to getpixel. The function now works correctly. int SaveScreenToFile(char* file) { int x,y; char spacer = 0; char pixel; char pal[16][3]={{0,0,0},{168,84,0},{0,168,84},{168,168,0},{0,84,168},{168,0,168} ,{0,84,168},{168,168,168}, {84,84,84},{252,0,0},{0,252,0},{252,252,0},{0,84,252},{252,0,252},{0,252,252 },{252,252,252}}; struct { char id[2]; long file_size,reserved,offset,header_size,width,height; short planes,bpp; long compression,bitmap_size,hres,vres,colors,important; } bmp; bmp.id[0]= 'B'; bmp.id[1]='M'; bmp.file_size = 22326; bmp.reserved = 0; bmp.offset = 118; bmp.header_size = 40; bmp.width = 640; bmp.height = 480; bmp.planes = 1; bmp.bpp = 4; bmp.compression = 0; bmp.bitmap_size = 22208; bmp.hres = 3780; bmp.vres = 3780; bmp.colors = 16; bmp.important = 16; FILE *out; out = fopen(file,"wb"); if (out == NULL) return(-1); fwrite(&bmp,sizeof(bmp),1,out); for (x = 0; x < 16; x++) { fputc(pal[x][RED],out); fputc(pal[x][GREEN],out); fputc(pal[x][BLUE],out); fputc(spacer,out); } for (y = (int)(bmp.height-1); y >= 0; y--) { for (x = 0; x <= (bmp.width-1); x++) { pixel = getpixel(x,y) << 4; x++; pixel += getpixel(x,y); fwrite(&pixel,sizeof(pixel),1,out); } } .