龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VC开发 >

VC中使用Gdi+合并jpg图片(2)

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
二。bmp图片合并 BOOL CombinePic(const WCHAR *format, const CString strDst, const CString strPic1, const CString strPic2) { BOOL bCombine = false; int nRet = 0; CLSID clsid; nRet = GetEncoderClsi

二。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;
}

例子:

CombinePic(L"image/bmp","12.bmp","1.bmp","2.bmp");

有了上面的功能,其他的就没问题了。

精彩图集

赞助商链接