if (strCmd == _T("水平拼图"))
{
//50张1000*1640的图像水平拼接
CImage *pImg = new CImage;
pImg->Create(1000*50, 1640, 8,0);
RGBQUAD* ColorTable;
int MaxColors = 256;
ColorTable = new RGBQUAD[MaxColors];
pImg->GetColorTable(0, MaxColors, ColorTable);
for (int i = 0; i<MaxColors; i++)
{
ColorTable[i].rgbBlue = (BYTE)i;
ColorTable[i].rgbGreen = (BYTE)i;
ColorTable[i].rgbRed = (BYTE)i;
}
pImg->SetColorTable(0, MaxColors, ColorTable);
delete[]ColorTable;
BYTE *pSrc = (BYTE*)pImg->GetBits();
int nPitch1 = pImg->GetPitch();
int height1 = pImg->GetHeight();
pSrc += (1639)*nPitch1;
int n = 10;
for (int i = 0; i < 50; i++)
{
CImage img;
CString str;
str.Format("C:\\拼图\\1 (%d).jpg", i + 1);
img.Load(str);
BYTE *p = (BYTE*)img.GetBits();
int nPitch = img.GetPitch();
int height = img.GetHeight();
p += (height - 1)*nPitch;
for (int j = 0; j < 1640; j++)
{
memcpy(pSrc-j*nPitch1+i * 1000, p + 1000 * j, 1000);
}
}
pImg->Save("C:\\kkk.jpg");
}
else if (strCmd == _T("竖直拼图"))
{
//50张2048*1000的图像竖直拼接
CImage *pImg = new CImage;
pImg->Create(2048, 1000*40, 8, 0);
RGBQUAD* ColorTable;
int MaxColors = 256;
ColorTable = new RGBQUAD[MaxColors];
pImg->GetColorTable(0, MaxColors, ColorTable);
for (int i = 0; i<MaxColors; i++)
{
ColorTable[i].rgbBlue = (BYTE)i;
ColorTable[i].rgbGreen = (BYTE)i;
ColorTable[i].rgbRed = (BYTE)i;
}
pImg->SetColorTable(0, MaxColors, ColorTable);
delete[]ColorTable;
BYTE *pSrc = (BYTE*)pImg->GetBits();
int nPitch1 = pImg->GetPitch();
int height1 = pImg->GetHeight();
pSrc += (999)*nPitch1;
int n = 10;
for (int i = 0; i < 40; i++)
{
CImage img;
CString str;
str.Format("C:\\拼图\\1 (%d).jpg", i + 1);
img.Load(str);
BYTE *p = (BYTE*)img.GetBits();
int nPitch = img.GetPitch();
int width = img.GetWidth();
int height = img.GetHeight();
p += (height - 1)*nPitch;
memcpy(pSrc , p, width*height);
pSrc += -width*height;
}
pImg->Save("C:\\kkk.jpg");
}
注意:拼接后的图像过大后,画图工具打不开。