Subj : Screen Capture function To : borland.public.cpp.borlandcpp From : Jeff Baker Date : Sat Jul 03 2004 05:30 pm I've been asked to insert a screen capture function into an existing DOS program and I'm having a little trouble. It seems to work fine except that the bmp it creates seems to be "zoomed in". The BMP header info is hard coded because it will always be the same so there is no need to acquire this information every time the user presses the capture key and I think I've done that part correctly (not 100% on that though) but if memory serves me correctly there was some shifting or something that has to be done with each pixel I just can't remember what it was. The source below uses the getpixel function even though I know its the slowest possible way to do it. Anyway if anybody has some time to look this over and offer a suggestion I would appreciate it. ---Additional Info--- 16-bit data types; Borland BGI 640x480x16 display driver/mode [START OF CODE] 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; short pal[48]; 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 = 22326L; 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 = 22208L; bmp.hres = 3780L; bmp.vres = 3780L; bmp.colors = 0; bmp.important = 0; pal[0] = 0; pal[1] = 0; pal[2] = 0; // Borland Color # 0 pal[3] = 42; pal[4] = 21; pal[5] = 0; // Borland Color # 1 pal[6] = 0; pal[7] = 42; pal[8] = 21; // Borland Color # 2 pal[9] = 42; pal[10] = 42; pal[11] = 0; // Borland Color # 3 pal[12] = 0; pal[13] = 21; pal[14] = 42; // Borland Color # 4 pal[15] = 42; pal[16] = 0; pal[17] = 42; // Borland Color # 5 pal[18] = 0; pal[19] = 22; pal[20] = 42; // Borland Color # 6 pal[21] = 42; pal[22] = 42; pal[23] = 42; // Borland Color # 7 pal[24] = 21; pal[25] = 21; pal[26] = 21; // Borland Color # 8 pal[27] = 63; pal[28] = 0; pal[29] = 0; // Borland Color # 9 pal[30] = 0; pal[31] = 63; pal[32] = 0; // Borland Color # 10 pal[33] = 63; pal[34] = 63; pal[35] = 0; // Borland Color # 11 pal[36] = 0; pal[37] = 21; pal[38] = 63; // Borland Color # 12 pal[38] = 63; pal[40] = 0; pal[41] = 63; // Borland Color # 13 pal[42] = 0; pal[43] = 63; pal[44] = 63; // Borland Color # 14 pal[45] = 63; pal[46] = 63; pal[47] = 63; // Borland Color # 15 FILE *out; out = fopen(file,"wb"); if (out == NULL) return(-1); fwrite(&bmp,sizeof(bmp),1,out); for (x = 0; x < 16; x++) { fputc((short)pal[0 + (x * 3)] << 2,out); fputc((short)pal[1 + (x * 3)] << 2,out); fputc((short)pal[2 + (x * 3)] << 2,out); fputc((short)spacer,out); } fseek(out,bmp.offset,SEEK_SET); for (y = (int)bmp.height; y > 0; y--) { for (x = 0; x < bmp.width; x++) { pixel = getpixel(x,y); fwrite(&pixel,sizeof(pixel),1,out); } } rewind(out); fclose(out); return(1); } [END OF CODE] .