您的位置:首页 > 其它

利用GDI+制作模糊效果

2008-04-15 12:55 399 查看
 在vista下,VS2008已经带了gdiplus1.1的库。

看看下面图片效果,是不是很神奇。

配置好GDIPLUS,你就可以在程序中实现了。



所以我们再也不用找一些算法来实现模糊,锐化,对比度,高亮等效果了

void CCatchScreenDlg::OnPaint()
{
 if (IsIconic())
 {
  CPaintDC dc(this); // device context for painting

  SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

  // Center icon in client rectangle
  int cxIcon = GetSystemMetrics(SM_CXICON);
  int cyIcon = GetSystemMetrics(SM_CYICON);
  CRect rect;
  GetClientRect(&rect);
  int x = (rect.Width() - cxIcon + 1) / 2;
  int y = (rect.Height() - cyIcon + 1) / 2;

  // Draw the icon
  dc.DrawIcon(x, y, m_hIcon);
 }
 else
 {
  Bitmap* pBmp = new Bitmap(L"background.bmp");//打开图片

  RECT rc = {0, 0, 100, pBmp->GetHeight()};

  Blur m_blur;

  BlurParams bp;

  bp.expandEdge = false;
  bp.radius = 5.0f;

  m_blur.SetParameters(&bp);

  pBmp->ApplyEffect(&m_blur, &rc);

  Graphics g(m_hWnd);

  g.DrawImage(pBmp, 0, 0);

  CDialog::OnPaint();
 }
}

如此简单。

你也来试试吧。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  gdi+ 算法