在知道位图数据和BITMAPINFO后,可以用SetDIBits()函数创建一位图句柄..然后在内存中准备一个hMemDC,在这上面把两张位图拼接成一块位图;
       代码如下:
InBlock.gif //这个函数在内存中构造一张位图,把两张位图拼接成一张.
InBlock.gifHBITMAP GetBmp()
InBlock.gif{
InBlock.gif    HBITMAP hBmp1, hBmp2;
InBlock.gif    SetDIBits(hBmp1, pStream1, bmpInfo1...); //得到位图1的句柄
InBlock.gif    SetDIBits(hBmp2, pStream2, bmpInfo2...); //得到位图2的句柄
InBlock.gif     //把这两张位图选入内存
InBlock.gif    HDC hDC1, hDC2;
InBlock.gif    SelectObject(hDC1, hBmp1);
InBlock.gif    SelectObject(hDC1, hBmp1);
InBlock.gif
InBlock.gif     //下面在内存中准备HDC ,和HBITMAP,用于拼接位图
InBlock.gif    HDC hMemDC;
InBlock.gif    HBITMAP hMemBmp = CreateCompatibleBitmap();
InBlock.gif    SelectObject(hMemDC, hMemBmp);
InBlock.gif     //下面就可以把这两张位图加载到这张准备好的内在位图中,调用函数BitBlt()
InBlock.gif    BitBlt(hMemDC, .... hDC1,...); //先把第一张位图选入内存
InBlock.gif    BitBlt(hMemDC, .... hDC2,...); //先把第二张位图选入内存
InBlock.gif     return hMemBmp;
InBlock.gif}
InBlock.gif //下面是把一张位图写入文件..代码来自MSDN
InBlock.gif void CreateBMPFile(HWND hwnd, LPTSTR pszFile, PBITMAPINFO pbi,    
InBlock.gif                                    HBITMAP hBMP, HDC hDC)    
InBlock.gif {    
InBlock.gif         HANDLE hf;                                 // file handle    
InBlock.gif        BITMAPFILEHEADER hdr;             // bitmap file-header    
InBlock.gif        PBITMAPINFOHEADER pbih;         // bitmap info-header    
InBlock.gif        LPBYTE lpBits;                             // memory pointer    
InBlock.gif        DWORD dwTotal;                             // total count of bytes    
InBlock.gif        DWORD cb;                                     // incremental count of bytes    
InBlock.gif        BYTE *hp;                                     // byte pointer    
InBlock.gif        DWORD dwTmp;    
InBlock.gif
InBlock.gif        pbih = (PBITMAPINFOHEADER) pbi;    
InBlock.gif        lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbih->biSizeImage);
InBlock.gif
InBlock.gif         if (!lpBits)    
InBlock.gif                 errhandler( "GlobalAlloc", hwnd);    
InBlock.gif
InBlock.gif         // Retrieve the color table (RGBQUAD array) and the bits    
InBlock.gif         // (array of palette indices) from the DIB.    
InBlock.gif         if (!GetDIBits(hDC, hBMP, 0, (WORD) pbih->biHeight, lpBits, pbi,    
InBlock.gif                DIB_RGB_COLORS))    
InBlock.gif        {
InBlock.gif                errhandler( "GetDIBits", hwnd);    
InBlock.gif        }
InBlock.gif
InBlock.gif         // Create the .BMP file.    
InBlock.gif        hf = CreateFile(pszFile,    
InBlock.gif                                     GENERIC_READ | GENERIC_WRITE,    
InBlock.gif                                     (DWORD) 0,    
InBlock.gif                                        NULL,    
InBlock.gif                                     CREATE_ALWAYS,    
InBlock.gif                                     FILE_ATTRIBUTE_NORMAL,    
InBlock.gif                                     (HANDLE) NULL);    
InBlock.gif         if (hf == INVALID_HANDLE_VALUE)    
InBlock.gif                errhandler( "CreateFile", hwnd);    
InBlock.gif        hdr.bfType = 0x4d42;                 // 0x42 = "B" 0x4d = "M"    
InBlock.gif         // Compute the size of the entire file.    
InBlock.gif        hdr.bfSize = (DWORD) ( sizeof(BITMAPFILEHEADER) +    
InBlock.gif                                 pbih->biSize + pbih->biClrUsed    
InBlock.gif                                 * sizeof(RGBQUAD) + pbih->biSizeImage);    
InBlock.gif        hdr.bfReserved1 = 0;    
InBlock.gif        hdr.bfReserved2 = 0;    
InBlock.gif
InBlock.gif         // Compute the offset to the array of color indices.    
InBlock.gif        hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) +    
InBlock.gif                                        pbih->biSize + pbih->biClrUsed    
InBlock.gif                                        * sizeof (RGBQUAD);    
InBlock.gif
InBlock.gif         // Copy the BITMAPFILEHEADER into the .BMP file.    
InBlock.gif         if (!WriteFile(hf, (LPVOID) &hdr, sizeof(BITMAPFILEHEADER),    
InBlock.gif                (LPDWORD) &dwTmp,    NULL))    
InBlock.gif        {
InBlock.gif             errhandler( "WriteFile", hwnd);    
InBlock.gif        }
InBlock.gif
InBlock.gif         // Copy the BITMAPINFOHEADER and RGBQUAD array into the file.    
InBlock.gif         if (!WriteFile(hf, (LPVOID) pbih, sizeof(BITMAPINFOHEADER)    
InBlock.gif                                    + pbih->biClrUsed * sizeof (RGBQUAD),    
InBlock.gif                                    (LPDWORD) &dwTmp, ( NULL))    
InBlock.gif                errhandler( "WriteFile", hwnd);    
InBlock.gif
InBlock.gif         // Copy the array of color indices into the .BMP file.    
InBlock.gif        dwTotal = cb = pbih->biSizeImage;    
InBlock.gif        hp = lpBits;    
InBlock.gif         if (!WriteFile(hf, (LPSTR) hp, ( int) cb, (LPDWORD) &dwTmp,NULL))    
InBlock.gif                     errhandler( "WriteFile", hwnd);    
InBlock.gif
InBlock.gif         // Close the .BMP file.    
InBlock.gif         if (!CloseHandle(hf))    
InBlock.gif                     errhandler( "CloseHandle", hwnd);    
InBlock.gif
InBlock.gif         // Free memory.    
InBlock.gif        GlobalFree((HGLOBAL)lpBits);
InBlock.gif}
本文出自 “ Paul玩嵌入式Linux” 博客,请务必保留此出处 http://zyg0227.blog.51cto.com/1043164/314505