本文只是把兩張等大小的bitmap圖左右拼接而已,基本操作,給大家一個參考。
直接上代碼
//1.獲得兩張圖片
CBitmap cbmp1,cbmp2;
cbmp1.LoadBitmap(IDB_BITMAP1);
cbmp2.LoadBitmap(IDB_BITMAP2);
BITMAP bmp1, bmp2;
int m_height = 0;
int m_width = 0;
cbmp1.GetBitmap(&bmp1); //cbmp1 轉換成CBitmap->BITMAP 結構體
long bitmapSize1 = bmp1.bmHeight * bmp1.bmWidthBytes;//字節數
BYTE* px1 = new BYTE[bitmapSize1];
DWORD nBytes1 = cbmp1.GetBitmapBits(bitmapSize1, px1);//把位圖的內容放入緩衝區px1中,返回值爲個數
for (int i = 0; i < bitmapSize1; i++)
{
BYTE temp = px1[i];
}
cbmp2.GetBitmap(&bmp2); //cbmp2 轉換成CBitmap->BITMAP 結構體
long bitmapSize2 = bmp2.bmHeight * bmp2.bmWidthBytes;
BYTE* px2 = new BYTE[bitmapSize2];
DWORD nBytes2 = cbmp2.GetBitmapBits(bitmapSize2, px2);//
if (bmp1.bmBitsPixel != 32 || bmp2.bmBitsPixel != 32)
{
::MessageBox(NULL, _T("此程序只能在 32 bit 顯示模式中顯示"), _T("警告"), 0);
return;
}
int rgb_b, x, y, i;
int PixelBytes = bmp1.bmBitsPixel / 8;//4個像素
BYTE* px3 = new BYTE[bitmapSize1 + bitmapSize2];
memcpy(px3, px1, bitmapSize1);
memcpy(px3 + bitmapSize1, px2, bitmapSize2);
//2.生成新圖片
CBitmap bmpNew;
bmpNew.CreateBitmap(bmp1.bmWidth+bmp2.bmWidth, bmp2.bmHeight,1,32, px3);
BITMAP bmNew;
bmpNew.GetBitmap(&bmNew);
int height = bmNew.bmHeight;
int width = bmNew.bmWidth;