//added by GMcD void SaveBitMapFile(void) { char title[256], filename[256], directory[256]; OPENFILENAME ofn; void *bits; BITMAPINFO *info; /* * Grab the screen bitmap... */ bits = ReadDIBitmap(&info); if (bits == NULL) { // DisplayErrorMessage("Unable to get OpenGL bitmap from screen!"); return; }; /* * Pop up a filename dialog... */ strcpy(directory, "."); strcpy(filename, "untitled.bmp"); strcpy(title, ""); memset(&ofn, 0, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = ViewWindow; ofn.lpstrFilter = "Models\0*.bmp\0\0"; ofn.nFilterIndex = 1; ofn.lpstrFile = filename; ofn.nMaxFile = sizeof(filename) - 1; ofn.lpstrFileTitle = title; ofn.nMaxFileTitle = sizeof(title) - 1; ofn.lpstrInitialDir = directory; ofn.lpstrTitle = "Save BitMap File"; ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_NONETWORKBUTTON; if (GetSaveFileName(&ofn)) { /* * Save the named model to disk... */ SaveDIBitmap(filename,info,bits); }; }
//************************************************************ // write a BMP file //************************************************************ void writeBmapFile(char *fullpath) { void *bits; BITMAPINFO *info; bits = ReadDIBitmap(&info); if (!bits) return; SaveDIBitmap(fullpath, info, bits); FREE(info); FREE(bits); }
static void SaveImage(const char *filename, bytemap_t *gray) { int i, sizeimage, widthbytes; unsigned char *image_buffer; BITMAPINFO *image_info; widthbytes = (gray->header.width*8+7)/8; sizeimage = (gray->header.height)*widthbytes; image_info = (BITMAPINFO *)malloc(sizeof(BITMAPINFO)+256*sizeof(RGBQUAD)); assert(image_info); *((RGBQUAD **)(&(image_info->bmiColors))) = (RGBQUAD *)(image_info+1); //memset(&image_info, 0, sizeof(BITMAPINFO)); //printf("info-header initialization\n"); image_info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); image_info->bmiHeader.biWidth = gray->header.width; image_info->bmiHeader.biHeight = -(gray->header.height); image_info->bmiHeader.biPlanes = 1; image_info->bmiHeader.biBitCount = 8; image_info->bmiHeader.biCompression = 0; image_info->bmiHeader.biSizeImage = sizeimage; image_info->bmiHeader.biXPelsPerMeter = 0; image_info->bmiHeader.biYPelsPerMeter = 0; image_info->bmiHeader.biClrUsed = 0; image_info->bmiHeader.biClrImportant = 0; //printf("palette initialization\n"); for (i = 0; i < 256; i++) { image_info->bmiColors[i].rgbBlue = i; image_info->bmiColors[i].rgbGreen = i; image_info->bmiColors[i].rgbRed = i; image_info->bmiColors[i].rgbReserved = 0; } //printf("pixel data initialization\n"); image_buffer = (unsigned char *)malloc(sizeimage); for (i = 0; i < gray->header.height; i++) { memcpy(image_buffer+i*widthbytes, gray->buffer+i*gray->header.pitch, gray->header.width); } SaveDIBitmap(filename, image_info, image_buffer); free(image_buffer); free(image_info); }