C++本人也是初学者,很多地方也不是很懂,写博客的原因主要有以下三个原因:
1.对于学习的得思路和资料进行整理
2.为比我还菜的朋友提供一定得参考
3.请优快云高手对我写的代码进行批评和指正。
图像的膨胀主要是利用光栅效果中的StretchBlt 的SRCCOPY光栅效果来制作,简单易懂。
图像水平膨胀式显示效果:
//图像水平膨胀式显示效果
void CGPShowView::OnHpopup()
{
if(m_ImageShow==NULL)
{
MessageBox("没有图像文件是不能执行此项操作的!","信息提示",MB_OK);
return;
}
CWaitCursor WaitCursor;
Invalidate();
CImage *pImage=&m_ImageShow;
int Width=pImage->GetWidth();
int Height=pImage->GetHeight();
CRect crect;
this->GetClientRect(&crect);
Width=Width<crect.Width()?Width:crect.Width();
Height=Height<crect.Height()?Height:crect.Height();
CMainFrame *pWnd=(CMainFrame*)AfxGetMainWnd();
pWnd->m_wndStatusBar.SetPaneText(0,"正在演示的是图像水平膨胀式显示效果",TRUE);
CClientDC *pDC=new CClientDC(this);
for(int i=0;i<Width;i+=Width/30)
{
pImage->StretchBlt(pDC->m_hDC,CRect(CPoint(i,0),CPoint(0,Height)),CRect(CPoint(0,0),CPoint(Width,Height)),SRCCOPY);
Sleep(10);
}
delete pDC;
}
图像垂直膨胀式显示效果:
//图像垂直膨胀式显示效果
void CGPShowView::OnVpopup()
{
if(m_ImageShow==NULL)
{
MessageBox("没有图像文件是不能执行此项操作的!","信息提示",MB_OK);
return;
}
CWaitCursor WaitCursor;
Invalidate();
CImage *pImage=&m_ImageShow;
int Width=pImage->GetWidth();
int Height=pImage->GetHeight();
CRect crect;
this->GetClientRect(&crect);
Width=Width<crect.Width()?Width:crect.Width();
Height=Height<crect.Height()?Height:crect.Height();
CMainFrame *pWnd=(CMainFrame*)AfxGetMainWnd();
pWnd->m_wndStatusBar.SetPaneText(0,"正在演示的是图像垂直膨胀式显示效果",TRUE);
CClientDC *pDC=new CClientDC(this);
for(int i=0;i<Height;i+=Height/30)
{
pImage->StretchBlt(pDC->m_hDC,CRect(CPoint(Width,Height-i),CPoint(0,Height)),CRect(CPoint(0,0),CPoint(Width,Height)),SRCCOPY);
Sleep(30);
}
delete pDC;
}
图像中心膨胀式显示效果:
//图像中心膨胀式显示效果
void CGPShowView::OnCpopup()
{
if(m_ImageShow==NULL)
{
MessageBox("没有图像文件是不能执行此项操作的!","信息提示",MB_OK);
return;
}
CWaitCursor WaitCursor;
Invalidate();
CImage *pImage=&m_ImageShow;
int Width=pImage->GetWidth();
int Height=pImage->GetHeight();
CRect crect;
this->GetClientRect(&crect);
Width=Width<crect.Width()?Width:crect.Width();
Height=Height<crect.Height()?Height:crect.Height();
CMainFrame *pWnd=(CMainFrame*)AfxGetMainWnd();
pWnd->m_wndStatusBar.SetPaneText(0,"正在演示的是图像中心膨胀式显示效果",TRUE);
CClientDC *pDC=new CClientDC(this);
for(int i=Height/4;i<Height;i+=Height/30)
{
pImage->StretchBlt(pDC->m_hDC, CRect(CPoint(Width/2-i*Width/Height,Height/2-i),CPoint(Width/2+i*Width/Height,Height/2+i)),CRect(CPoint(0,0),CPoint(Width,Height)),SRCCOPY);
Sleep(30);
}
delete pDC;
}
图像部分膨胀式显示效果:
//图像部分膨胀式显示效果
void CGPShowView::OnPpopup()
{
if(m_ImageShow==NULL)
{
MessageBox("没有图像文件是不能执行此项操作的!","信息提示",MB_OK);
return;
}
CWaitCursor WaitCursor;
Invalidate();
CImage *pImage=&m_ImageShow;
int Width=pImage->GetWidth();
int Height=pImage->GetHeight();
CRect crect;
this->GetClientRect(&crect);
Width=Width<crect.Width()?Width:crect.Width();
Height=Height<crect.Height()?Height:crect.Height();
CMainFrame *pWnd=(CMainFrame*)AfxGetMainWnd();
pWnd->m_wndStatusBar.SetPaneText(0,"正在演示的是图像部分膨胀式显示效果",TRUE);
CClientDC *pDC=new CClientDC(this);
pImage->Draw(pDC->m_hDC,CPoint(0,0));
for(int i=Width/3;i<Width;i++)
{
pImage->StretchBlt(pDC->m_hDC,CRect(0,0,i,(double)Height/Width*i),CRect(0,0,Width/3,Height/3));
Sleep(10);
}
pImage->Draw(pDC->m_hDC,CPoint(0,0));
for(int i=Width/3;i>0;i--)
{
pImage->StretchBlt(pDC->m_hDC,CRect(i,0,Width-i,(double)Height/Width*(Width-i)),CRect(Width/3,0,Width*2/3,Height/3));
Sleep(20);
}
pImage->Draw(pDC->m_hDC,CPoint(0,0));
for(int i=Width*2/3;i>0;i--)
{
pImage->StretchBlt(pDC->m_hDC,CRect(i,0,Width,(double)Height/Width*(Width-i)),CRect(Width*2/3,0,Width,Height/3));
Sleep(10);
}
delete pDC;
}
代码很简单,但是图像的效果还是不错,建议新手动手写写。
StretchBlt最后一个参数(dwRop)
Specifies the raster operation to be performed. Raster operation codes define how GDI combines colors in output operations that involve a current brush, a possible source bitmap, and a destination bitmap. This parameter may be one of the following values:
执行指定的光栅操作,光栅操作定义了用最近的画刷将源图用颜色集合输出目标图。参数可以为下面的值。
-
BLACKNESS Turns all output black.
-
DSTINVERT Inverts the destination bitmap.
-
MERGECOPY Combines the pattern and the source bitmap using the Boolean AND operator.
-
MERGEPAINT Combines the inverted source bitmap with the destination bitmap using the Boolean OR operator.
-
NOTSRCCOPY Copies the inverted source bitmap to the destination.
-
NOTSRCERASE Inverts the result of combining the destination and source bitmaps using the Boolean OR operator.
-
PATCOPY Copies the pattern to the destination bitmap.
-
PATINVERT Combines the destination bitmap with the pattern using the Boolean XOR operator.
-
PATPAINT Combines the inverted source bitmap with the pattern using the Boolean OR operator. Combines the result of this operation with the destination bitmap using the Boolean OR operator.
-
SRCAND Combines pixels of the destination and source bitmaps using the Boolean AND operator.
-
SRCCOPY Copies the source bitmap to the destination bitmap.
-
SRCERASE Inverts the destination bitmap and combines the result with the source bitmap using the Boolean AND operator.
-
SRCINVERT Combines pixels of the destination and source bitmaps using the Boolean XOR operator.
-
SRCPAINT Combines pixels of the destination and source bitmaps using the Boolean OR operator.
-
WHITENESS Turns all output white.
本人也在学习GDI+,写得比较简单,让高手见笑了。欢迎高手给我指点
QQ:125941562
注:欢迎转载,请保留上面的作者信息