求助:图像拼接
我要写图像拼接方面的论文,就是把两幅图拼接成一幅,不知道怎么用VC来实现,哪位有这方面的资料,可以传点给我吗?我的邮箱是:junzi511@163.com
[解决办法]
bmp图片合并
BOOL CombinePic(const WCHAR *format, const CString &strDst, const CString &strPic1, \
const CString &strPic2)
{
BOOL bCombine = false;
int nRet = 0;
CLSID clsid;
nRet = GetEncoderClsid(format,&clsid);
if (nRet> =0)
{
USES_CONVERSION;
Bitmap bmp1(A2W(strPic1));
Bitmap bmp2(A2W(strPic2));
int nWidth = 0, nHeight = 0;
nWidth = bmp1.GetWidth(); //假设两图片大小同
nHeight = bmp1.GetHeight();
Bitmap bmpCombine(2*nWidth,nHeight); //高不变,宽*2,水平合并
Graphics * pG = NULL;
pG = Graphics::FromImage(&bmpCombine);
if (pG!=NULL)
{
pG-> DrawImage(&bmp1,0,0);
pG-> DrawImage(&bmp2,nWidth,0);
bmpCombine.Save(A2W(strDst),&clsid,NULL);
}
}
return bCombine;
}
int GetEncoderClsid(const WCHAR *format, CLSID *pClsid)
{
int nRet = -1;
ImageCodecInfo * pCodecInfo = NULL;
UINT nNum = 0,nSize = 0;
GetImageEncodersSize(&nNum,&nSize);
if (nSize <0)
{
return nRet;
}
pCodecInfo = new ImageCodecInfo[nSize];
if (pCodecInfo==NULL)
{
return nRet;
}
GetImageEncoders(nNum,nSize,pCodecInfo);
for (UINT i=0; i <nNum; i++)
{
if (wcscmp(pCodecInfo[i].MimeType,format)==0)
{
*pClsid = pCodecInfo[i].Clsid;
nRet = i;
delete[] pCodecInfo;
return nRet;
}
else
{
continue;
}
}
delete[] pCodecInfo;
return nRet;
}
例子:
CombinePic(L "image/bmp ", "12.bmp ", "1.bmp ", "2.bmp ");
这是GDI+做的,有GDI+的初始化和销毁工作要做,网上有这方面的资料。