WEB开发网
开发学院软件开发VC 图像与文字的合成 阅读

图像与文字的合成

 2010-07-25 20:46:59 来源:WEB开发网   
核心提示:二、关键程序段CreateMemObject(CDC *pDC, BITMAPINFO *lpbmi, int* pnLineChar){if (NULL == m_pMemDC){m_pMemDC = new CDC();m_pMemDC->CreateCompatibleDC(pDC);}if (m_pMem

二、关键程序段

CreateMemObject(CDC *pDC, BITMAPINFO *lpbmi, int* pnLineChar)
{
  if (NULL == m_pMemDC)
  {
    m_pMemDC = new CDC();
    m_pMemDC->CreateCompatibleDC(pDC);
  }
  if (m_pMemBmp != NULL)
  {
    m_pMemDC->SelectObject(m_pOldBmp);
    delete m_pMemBmp;
    m_pMemBmp = NULL;
  }
  m_pMemBmp = new CBitmap();    //根据图片的大小创建一个兼容位图
  m_pMemBmp->CreateCompatibleBitmap(pDC, m_lpBMPHdr->biWidth, m_lpBMPHdr->biHeight);
  m_pOldBmp = m_pMemDC->SelectObject(m_pMemBmp);
  m_pMemDC->FillSolidRect(0, 0, m_lpBMPHdr->biWidth, m_lpBMPHdr->biHeight, RGB(255, 255, 255));

    //把图像的数据绘制到兼容位图上

  SetDIBits(m_pMemDC->GetSafeHdc(), (HBITMAP)m_pMemBmp->m_hObject,
    0, m_lpBMPHdr->biHeight, (LPVOID)m_lpDIBits, (BITMAPINFO*)m_lpBMPHdr, DIB_RGB_COLORS);
}
SetBmpText(const CString &strText, BOOL bRepaint)
{
  //本函数在位图上添加文本
  m_strBmpText = strText;

  SetDIBits(m_pMemDC->GetSafeHdc(), (HBITMAP)m_pMemBmp->m_hObject,
    0, m_lpBMPHdr->biHeight, (LPVOID)m_lpDIBits, (BITMAPINFO*)m_lpBMPHdr, DIB_RGB_COLORS);
  if (m_strBmpText.GetLength() > 0)
  {
    //制造透明和重影效果
    m_pMemDC->SetBkMode(TRANSPARENT);
    m_pMemDC->SetTextColor(RGB(0, 0, 0));
    m_pMemDC->TextOut(10, 10, m_strBmpText);
    m_pMemDC->SetTextColor(RGB(255, 255, 255));
    m_pMemDC->TextOut(11, 11, m_strBmpText);
  }
  if (bRepaint)
  {
    Invalidate();
  }
}
SetSaveBmpPath(LPCTSTR pszPath)
{
  //从兼容位图中取出合成的数据
  BYTE *pTemp = new BYTE[m_dwImageSize];
  ZeroMemory(pTemp, m_dwImageSize);

  int nCount = GetDIBits(m_pMemDC->GetSafeHdc(),
    (HBITMAP)m_pMemBmp->m_hObject, 0, m_lpBMPHdr->biHeight,
    (LPVOID)pTemp, (BITMAPINFO*)m_lpBMPHdr, DIB_RGB_COLORS);
}

Tags:图像 文字 合成

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接