1.
//_lseek(file_handle, -(int)pbitmap->bitmapinfoheader.biSizeImage, SEEK_END);
SetFilePointer((HANDLE)file_handle, -(int)(pbitmap->bitmapinfoheader.biSizeImage), NULL, FILE_END);
http://bbs.csdn.net/topics/270065223
http://blog.csdn.net/aloneone/article/details/21245443
2.
windows游戏编程大师基本都是使用DIRECTDRAW全屏,8位模式。
读BMP文件存放到自定义的机构体,那么显示图片时就是进行内存拷贝了。而window api基本讲的都是DC。
typedef struct BITMAP_FILE_TAG { BITMAPFILEHEADER bitmapfileheader; // this contains the bitmapfile header BITMAPINFOHEADER bitmapinfoheader; // this is all the info including the palette PALETTEENTRY palette[256]; // we will store the palette here UCHAR *buffer; // this is a pointer to the data } BITMAP_FILE, *BITMAP_FILE_PTR; int Load_Bitmap_File(BITMAP_FILE_PTR bitmap, char *filename) 。。。
DEMO7_12.CPP 24-bit bitmap loading demo
bitmap是24位,lpddsprimary是32位,将bitmap的一个像素点(占3位),放到DWORD(占4位),拷贝到primary_buffer。就可以显示图片了。
#define SCREEN_BPP 32 // bits per pixel
// process each line and copy it into the primary buffer for (int index_y = 0; index_y < SCREEN_HEIGHT; index_y++) { for (int index_x = 0; index_x < SCREEN_WIDTH; index_x++) { // get BGR values UCHAR blue = (bitmap.buffer[index_y*SCREEN_WIDTH*3 + index_x*3 + 0]), green = (bitmap.buffer[index_y*SCREEN_WIDTH*3 + index_x*3 + 1]), red = (bitmap.buffer[index_y*SCREEN_WIDTH*3 + index_x*3 + 2]); // this builds a 32 bit color value in A.8.8.8 format (8-bit alpha mode) DWORD pixel = _RGB32BIT(0,red,green,blue); // write the pixel primary_buffer[index_x + (index_y*ddsd.lPitch >> 2)] = pixel; } // end for index_x } // end for index_y
windows dc
BOOL CDDraw::LoadBMPSurface(LPDIRECTDRAWSURFACE7 &lpSurf, //要载入图像的表面指针 LPCSTR BitmapFile )//源图像的路径 { HDC hdcImage; HDC hdc; HBITMAP hbm; BITMAP bm; HRESULT ddrval; if( lpSurf == NULL ) return FALSE; // 将位图作为文件来读取 hbm = (HBITMAP)LoadImage(NULL, BitmapFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); if (hbm == NULL){ //载入图像失败时进到这里来 //在这里可以记录载入图像失败的信息 return FALSE; } //函数功能:创建一个与指定设备兼容的内存设备上下文环境(Device Context) //创建一个与应用程序的当前显示器兼容的内存设备上下文环境 hdcImage = CreateCompatibleDC(NULL); if (!hdcImage){ //创建设备上下文出错 return FALSE; } //选择位图对象到刚刚创建的内存设备上下文环境(DC) SelectObject(hdcImage, hbm); //获取位图宽与高 GetObject(hbm, sizeof(bm), &bm); //获取表面的宽与高 DDSURFACEDESC2 ddsd; ddsd.dwSize = sizeof(ddsd); lpSurf->GetSurfaceDesc(&ddsd); if( BitmapFile!=NULL ) { if ((ddrval = lpSurf->GetDC(&hdc)) == DD_OK) { //将源位图复制到表面,可以进行拉伸或收缩 StretchBlt( hdc, 0, 0, ddsd.dwWidth, ddsd.dwHeight, hdcImage, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY); lpSurf->ReleaseDC(hdc); } } DeleteDC(hdcImage); if( ddrval != DD_OK ) { //复制矩形块失败 return FALSE; } return TRUE; }