Subj : Re: Screen Capture function To : borland.public.cpp.borlandcpp From : Jeff Baker Date : Sat Jul 03 2004 06:39 pm First, thanks Bob for the quick response. For clarity, I'm taking your advice with the pal array. The reason for the rewind statement was because I was closing the file then re-loading it to check the header information. That was an earlier draft, it's now removed. You were also correct about the for loops starting and ending incorrectly, that's now fixed. I'm not sure what you mean by "pad" but I'll have to figure it out because with all your suggestions (other then padding) it performs the same. typedef 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_file; #define RED 0 #define GREEN 1 #define BLUE 2 char pal[16][3]={ {0,0,0}, // Borland Color # 0 {42,21,0}, // Borland Color # 1 {0,42,21}, // Borland Color # 2 {42,42,0}, // Borland Color # 3 {0,21,42}, // Borland Color # 4 {42,0,42}, // Borland Color # 5 {0,21,42}, // Borland Color # 6 {42,42,42},// Borland Color # 7 {21,21,21},// Borland Color # 8 {63,0,0}, // Borland Color # 9 {0,63,0}, // Borland Color # 10 {63,63,0}, // Borland Color # 11 {0,21,63}, // Borland Color # 12 {63,0,63}, // Borland Color # 13 {0,63,63}, // Borland Color # 14 {63,63,63}}; // Borland Color # 15 bmp_file bmp; int SaveScreenToFile(char* file) { int x,y; short spacer = 0; unsigned char pixel; 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 = 0; bmp.important = 0; 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] << 2,out); fputc(pal[x][GREEN] << 2,out); fputc(pal[x][BLUE] << 2,out); fputc((short)spacer,out); } for (y = (bmp.height-1); y >= 0; y--) { for (x = 0; x <= (bmp.width-1); x++) { pixel = getpixel(x,y); fwrite(&pixel,sizeof(pixel),1,out); } } fclose(out); return(1); } "Bob Gonder" wrote in message news:aukbe0ltjv54ibrmm3gp81q7nhm4d1c4k3@4ax.com... > Jeff Baker wrote: > > >anybody has some time to look this over and offer a suggestion I would > >appreciate it. > > Couple observasions without looking into the validity of your BMP. > > >pal[0] = 0; pal[1] = 0; pal[2] = 0; // Borland Color # 0 > > Pallets are usually RGB structs. Or you could be more clear as in > char pal[16][3] = { {0,0,0}, // Borland Color # 0 > {42,21,0}, // Borland Color # 1 > {0,42,21}, // Borland Color # 2 > . . . . > {63,63,63} }; // Borland Color # 15 > > >for (x = 0; x < 16; x++) > > { > > fputc((short)pal[0 + (x * 3)] << 2,out); > fputc( pal[x][0], out ); > > >fseek(out,bmp.offset,SEEK_SET); > > Don't Seek that which you haven't written. > If the above writing doesn't put you in the proper place, write some > more (or less, as the case may be). > > >for (y = (int)bmp.height; y > 0; y--) > > Don't you want to go to zero? > You start too high and end too soon. > > > { > > for (x = 0; x < bmp.width; x++) > > { > > pixel = getpixel(x,y); > > fwrite(&pixel,sizeof(pixel),1,out); > > I think BMP.Width _must_ be 8 pixel boundry. > Pad if width%8 != 0 > > >rewind(out); > > What is this? Reel-To-Reel tape? > Don't rewind before closing. > Don't rewind unless you have a reason to do so (hardly ever). > > .