【正文】
39。t get memory block if (!hDIB) { // clean up and return NULL SelectPalette(hDC, hPal, TRUE)。 RealizePalette(hDC)。 ReleaseDC(NULL, hDC)。 return NULL。 } // lock memory and get pointer to it lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIB)。 /// use our bitmap info. to fill BITMAPINFOHEADER *lpbi = bi。 // call GetDIBits with a NULL lpBits param, so it will calculate the // biSizeImage field for us GetDIBits(hDC, hBitmap, 0, (UINT), NULL, (LPBITMAPINFO)lpbi, DIB_RGB_COLORS)。 // get the info. returned by GetDIBits and unlock memory block bi = *lpbi。 GlobalUnlock(hDIB)。 // if the driver did not fill in the biSizeImage field, make one up if ( == 0) = WIDTHBYTES((DWORD) * biBits) * 。 // realloc the buffer big enough to hold all the bits dwLen = + PaletteSize((LPBYTE)amp。bi) + 。 if (h = GlobalReAlloc(hDIB, dwLen, 0)) hDIB = h。 else { 理學學士學位論文 第二章 分形 相關 理 論 問題 19 // clean up and return NULL GlobalFree(hDIB)。 hDIB = NULL。 SelectPalette(hDC, hPal, TRUE)。 RealizePalette(hDC)。 ReleaseDC(NULL, hDC)。 return NULL。 } // lock memory block and get pointer to it */ lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIB)。 // call GetDIBits with a NONNULL lpBits param, and actualy get the // bits this time if (GetDIBits(hDC, hBitmap, 0, (UINT), (LPBYTE)lpbi + (WORD)lpbibiSize + PaletteSize((LPBYTE)lpbi), (LPBITMAPINFO)lpbi, DIB_RGB_COLORS) == 0) { // clean up and return NULL GlobalUnlock(hDIB)。 hDIB = NULL。 SelectPalette(hDC, hPal, TRUE)。 RealizePalette(hDC)。 ReleaseDC(NULL, hDC)。 return NULL。 } bi = *lpbi。 // clean up GlobalUnlock(hDIB)。 SelectPalette(hDC, hPal, TRUE)。 RealizePalette(hDC)。 ReleaseDC(NULL, hDC)。 理學學士學位論文 第二章 分形 相關 理 論 問題 20 // return handle to the DIB return hDIB。 } bool CGlobal::SaveDIB(HANDLE hDib, LPCTSTR lpFileName) { BITMAPFILEHEADER bmfHdr。 // Header for Bitmap file LPBITMAPINFOHEADER lpBI。 // Pointer to DIB info structure HANDLE fh。 // file handle for opened file DWORD dwDIBSize。 DWORD dwWritten。 if (!hDib) return FALSE。 fh = CreateFile(lpFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL)。 if (fh == INVALID_HANDLE_VALUE) return FALSE。 // Get a pointer to the DIB memory, the first of which contains // a BITMAPINFO structure lpBI = (LPBITMAPINFOHEADER)GlobalLock(hDib)。 if (!lpBI) { CloseHandle(fh)。 return FALSE。 } // Check to see if we39。re dealing with an OS/2 DIB. If so, don39。t // save it because our functions aren39。t written to deal with these // DIBs. if (lpBIbiSize != sizeof(BITMAPINFOHEADER)) { 理學學士學位論文 第二章 分形 相關 理 論 問題 21 GlobalUnlock(hDib)。 CloseHandle(fh)。 return FALSE。 } // Fill in the fields of the file header // Fill in file type (first 2 bytes must be BM for a bitmap) = DIB_HEADER_MARKER。 // BM dwDIBSize = *(LPDWORD)lpBI + PaletteSize((LPBYTE)lpBI)。 // Now calculate the size of the image // It39。s an RLE bitmap, we can39。t calculate size, so trust the biSizeImage // field if ((lpBIbiCompression == BI_RLE8) || (lpBIbiCompression == BI_RLE4)) dwDIBSize += lpBIbiSizeImage。 else { DWORD dwBmBitsSize。 // Size of Bitmap Bits only // It39。s not RLE, so size is Width (DWORD aligned) * Height dwBmBitsSize = WIDTHBYTES((lpBIbiWidth)*((DWORD)lpBIbiBitCount)) * lpBIbiHeight。 dwDIBSize += dwBmBitsSize。 // Now, since we have calculated the correct size, why don39。t we // fill in the biSizeImage field (this will fix any .BMP files which // have this field incorrect). lpBIbiSizeImage = dwBmBitsSize。 } // Calculate the file size by adding the DIB size to sizeof(BITMAPFILEHEADER) = dwDIBSize + sizeof(BITMAPFILEHEADER)。 = 0。 = 0。 理學學士學位論文 第二章 分形 相關 理 論 問題 22 // Now, calculate the offset the actual bitmap bits will be in // the file It39。s the Bitmap file header plus the DIB header, // plus the size of the color table. = (DWORD)sizeof(BITMAPFILEHEADER) + lpBIbiSize +PaletteSize((LPBYTE)lpBI)。 // Write the file header WriteFile(fh,(LPBYTE)amp。bmfHdr,sizeof(BITMAPFILEHEADER), amp。dwWritten, NULL)。 // Write the DIB header and the bits use local version of // MyWrite, so we can write more than 32767 bytes of data WriteFile(fh, (LPBYTE)lpBI, dwDIBSize, amp。dwWritten, NULL)。 GlobalUnlock(hDib)。 CloseHandle(fh)。 if (dwWritten == 0) return FALSE。 // oops, something happened in the write else return TRUE。 // Success code } 理學學士學位論文 第三章 畢業(yè)設計結(jié)果與分析 23 第三章 畢業(yè)設計結(jié)果和分析 給出畢業(yè)設計的結(jié)果圖,并給出適當?shù)姆治?,指出其?yōu)勢和不足之處。 程序概況 本程序共分為以下四個主菜單: 1, 文件:主要是有關文件的操作。 子菜單: ○ 1 新建:新建一個視圖。 ○ 2 保存 : 保存當前圖片。 ○ 3 退出 : 退出當前程序。 2, 查看:用于選定查看的分形圖形類型。 子菜單: ○ 1 Julia 集:查看 Julia 集圖。 圖 ○ 2 Mandelbrot 集:查看 Mandelbrot 集。 理學學士學位論文 第三章 畢業(yè)設計結(jié)果與分析 24