#include #include"bmp_io.h" BMP_IO::BMP_IO() { lpPixel=NULL; } BMP_IO::~BMP_IO() { DeleteObject(hdcBMP); } BOOL BMP_IO::bmp_in(LPCTSTR file_name,HWND hWnd) { fhBMP=CreateFile(file_name,GENERIC_READ,0,NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if(fhBMP==INVALID_HANDLE_VALUE){ MessageBox(hWnd,"ファイルが開けません","エラー",MB_OK); return FALSE; } iFileSize=GetFileSize(fhBMP,NULL); lpBMP=(LPBYTE)HeapAlloc(GetProcessHeap(),0,iFileSize); ReadFile(fhBMP,lpBMP,iFileSize,&dwRead,NULL); CloseHandle(fhBMP); lpbmpfh=(LPBITMAPFILEHEADER)(lpBMP); lpbiBMPInfo=(LPBITMAPINFO)(lpBMP+sizeof(BITMAPFILEHEADER)); if(lpbmpfh->bfType!=('M'<<8)+'B' || lpbiBMPInfo->bmiHeader.biBitCount!=8){ MessageBox(hWnd,"8ビットBMPファイルしか読み込めません","エラー",MB_OK); HeapFree(GetProcessHeap(),0,lpBMP); return FALSE; } iOffset=lpbmpfh->bfOffBits; lpBMPPixel=lpBMP+iOffset; dwColors=(LPDWORD)lpbiBMPInfo->bmiColors; iWidth=lpbiBMPInfo->bmiHeader.biWidth; iHeight=lpbiBMPInfo->bmiHeader.biHeight; biInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER); biInfo.bmiHeader.biWidth=iWidth; biInfo.bmiHeader.biHeight=iHeight; biInfo.bmiHeader.biPlanes=1; biInfo.bmiHeader.biBitCount=32; biInfo.bmiHeader.biCompression=BI_RGB; if(lpPixel!=NULL) DeleteObject(hdcBMP); hdc=GetDC(hWnd); hBMP=CreateDIBSection(hdc,&biInfo,DIB_RGB_COLORS, (LPVOID *)(&lpPixel),NULL,0); hdcBMP=CreateCompatibleDC(hdc); SelectObject(hdcBMP,hBMP); ReleaseDC(hWnd,hdc); DeleteObject(hBMP); for(y=0;y