//"DibImage.h"
#if !defined(AFX_DIBIMAGE_H__254F3D1E_BB20_40DA_AE07_E8E0219DFA8C__INCLUDED_)
#define AFX_DIBIMAGE_H__254F3D1E_BB20_40DA_AE07_E8E0219DFA8C__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
DECLARE_HANDLE(HDIB); // DIB句柄
//幾個用到的函數聲明,做全局函數使用
HGLOBAL CopyHandle (HGLOBAL h);
Word WINAPI GetPaletteSize(LPSTR lpbi);
BOOL WINAPI SaveToFile(HANDLE hDib, CFile& file);
#endif
//DibImage.cpp
#include "stdafx.h"
#include "DPASSUB.h"
#include"DibImage.h"
HGLOBAL CopyHandle (HGLOBAL h)
{
if (h == NULL)
{
return NULL;
}
DWord dwLen =GlobalSize((HGLOBAL) h); // 獲取指定內存區域大小
HGLOBAL hCopy = GlobalAlloc(GHND, dwLen); // 分配新內存空間
if (hCopy != NULL) // 判斷分配是否成功
{
void* lpCopy = GlobalLock((HGLOBAL) hCopy);
void* lp = GlobalLock((HGLOBAL) h);
memcpy(lpCopy, lp, dwLen);
GlobalUnlock(hCopy);
GlobalUnlock(h);
}
return hCopy;
}
Word WINAPI GetPaletteSize(LPSTR lpbi)
{
DWord dwClrUsed;
dwClrUsed=((LPBITMAPINFOHEADER)lpbi)->biClrUsed;
if (dwClrUsed == 0)
switch ( ((LPBITMAPINFOHEADER)lpbi)->biBitCount )
{
case 1:
dwClrUsed=2;
break;
case 4:
dwClrUsed=16;
break;
case 8:
dwClrUsed=256;
break;
default:
dwClrUsed=0;
break;
}
return (Word)(dwClrUsed * sizeof(RGBQUAD));
}
BOOL WINAPI SaveToFile(HANDLE hDib, CFile& file)
{
BITMAPFILEHEADER bmfHdr;
LPBITMAPINFOHEADER lpBI;
DWord dwDIBSize;