#include //8ビットBMPを32ビットDIBに読み込む関数 //戻り値:ピクセル列を指すポインタ(正常) or NULL(エラー) LPDWORD bmp8toDIB(char *fileName,LPBITMAPINFO lpbiInfo) { HANDLE fhBMP; int iFileSize; LPBYTE lpBMP; DWORD dwReadSize; LPBITMAPFILEHEADER lpbmpfh; LPBITMAPINFO lpbiBMPInfo; LPBYTE lpBMPPixel; LPDWORD dwColors; int iWidth,iHeight; LPDWORD lpPixel; int iLength,x,y; fhBMP=CreateFile(fileName,GENERIC_READ,0,NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if(fhBMP==INVALID_HANDLE_VALUE){ CloseHandle(fhBMP); MessageBox(NULL,"ファイルが開けません",fileName,MB_OK); return NULL; } iFileSize=GetFileSize(fhBMP,NULL); lpBMP=(LPBYTE)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,iFileSize); ReadFile(fhBMP,lpBMP,iFileSize,&dwReadSize,NULL); CloseHandle(fhBMP); lpbmpfh=(LPBITMAPFILEHEADER)(lpBMP); lpbiBMPInfo=(LPBITMAPINFO)(lpBMP+sizeof(BITMAPFILEHEADER)); if(lpbmpfh->bfType!=('M'<<8)+'B' || lpbiBMPInfo->bmiHeader.biBitCount!=8){ HeapFree(GetProcessHeap(),0,lpBMP); MessageBox(NULL,"8ビットBMPファイルしか読み込めません",fileName,MB_OK); return NULL; } lpBMPPixel=lpBMP+(lpbmpfh->bfOffBits); dwColors=(LPDWORD)(lpbiBMPInfo->bmiColors); iWidth=lpbiBMPInfo->bmiHeader.biWidth; iHeight=lpbiBMPInfo->bmiHeader.biHeight; lpPixel=(LPDWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,iWidth*iHeight*4); lpbiInfo->bmiHeader.biSize=sizeof(BITMAPINFOHEADER); lpbiInfo->bmiHeader.biWidth=iWidth; lpbiInfo->bmiHeader.biHeight=iHeight; lpbiInfo->bmiHeader.biPlanes=1; lpbiInfo->bmiHeader.biBitCount=32; lpbiInfo->bmiHeader.biCompression=BI_RGB; if(iWidth%4) iLength=iWidth+(4-iWidth%4); //横幅は4の倍数バイトでなければならない else iLength=iWidth; for(y=0;y