Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!sun-barr!decwrl!hplabs!hp-pcd!hpcvlx!bturner From: bturner@hpcvlx.HP.COM (Bill Turner) Newsgroups: comp.windows.ms Subject: Re: Saving Bitmaps Message-ID: <106580058@hpcvlx.HP.COM> Date: 4 Aug 89 16:44:29 GMT References: <30368@ucbvax.BERKELEY.EDU> Organization: Hewlett-Packard Co., Corvallis, OR, USA Lines: 40 > Hi, I am working on a program that uses a big color bitmap, I would like > to save this bitmap when my application is iconified so that I can free > up the memory, how would I go about dumping a bitmap to a disk and then > reading it from a disk Create a compatable DC for the display, and a compatible bitmap (NOTE! large color bitmaps take lots of memory, so you may want to do this in "bands", slicing the full image into smaller pieces). BitBlt from the display to the memory DC, then use GetBitmapBits to get a memory copy of the bitmap, which can be written to a file. To restore the picture, read the file into memory, use SetBitmapBits to copy them into a memory bitmap, then BitBlt to the display. BYTE buffer[]; hMemDC = CreateCompatibleDC(hDC); hMemBits = CreateCompatibleBitmap(hDC, nWidth, nHeight); /* Note below */ SelectObject(hMemDC, hMemBits); BitBlt(hMemDC, xDest, yDest, nWidth, nHeight, hDC, xSrc, ySrc, SRCCOPY); /* Note below */ dSize = GetBitmapBits(hMemBits, sizeof(buffer), buffer); /* Now you have the bits in buffer */ DeleteDC(hMemDC); DeleteObject(hMemBits); NOTES: CreateCompatibleBitmap will create a bitmap compatible with a device iff a device DC is used. If you had done CreateCompatibleBitmap(hMemDC,...), then the bitmap would have been monochrome. In the BitBlt, xDest and yDest will probably be (0, 0). If you will be banding, repeat the BitBlt/GetBitmapBits as required. CAVEAT: The format of color bitmaps isn't as standard as that for monochrome. If you save an EGA color bitmap, don't expect to be able to restore it onto a CGA display. --Bill Turner (bturner@hp-pcd.hp.com) HP Corvallis Information Systems