Windows界面编程第九篇 位图显示特效 交错效果

转载请标明出处,原文地址:http://blog.csdn.net/morewindows/article/details/8696720

欢迎关注微博:http://weibo.com/MoreWindows

  

    位图显示特效是大一时刚接触Windows VC++编程时作为练习作业写的,当时觉得一个简单至极的BitBlt函数居然也能和动画扯上关系,确实很有创意^_^(大一太菜了)。呵呵,转眼之间都要毕业,现在整理出来,供大家娱乐娱乐。

Windows界面编程之位图显示特效系列目录:

1. Windows界面编程第九篇位图显示特效交错效果》

http://blog.csdn.net/morewindows/article/details/8696720

2. Windows界面编程第十篇位图显示特效百叶窗效果》

http://blog.csdn.net/morewindows/article/details/8696722

3. Windows界面编程第十一篇位图显示特效随机积木效果》

http://blog.csdn.net/morewindows/article/details/8696724

4. Windows界面编程第十二篇位图显示特效飞入效果与伸展效果》

http://blog.csdn.net/morewindows/article/details/8696726

5. Windows界面编程第十三篇位图显示特效合集》

http://blog.csdn.net/morewindows/article/details/8696730

 

 

       本篇《Windows界面编程第九篇位图显示特效交错效果》将讲解位图的交错显示效果。如下图所示:

水平交错(图片不能打开,请访问http://blog.csdn.net/morewindows/article/details/8696720

垂直交错(图片不能打开,请访问http://blog.csdn.net/morewindows/article/details/8696720

 

       在程序设计上,水平交错只要将图像分为奇数行和偶数行,然后一个从上到下,一个从下到上逐渐显示出来即可。垂直交错只要将图像分为奇数列和偶数列,然后一个从左到右,一个从右到左逐渐显示出来即可。

       下面给出代码:

// 交错 - 水平
//《Windows界面编程第九篇 位图显示特效 交错效果》
//http://blog.csdn.net/morewindows/article/details/8696720
void AnimateDraw_StaggeredHorizontal(HDC hdc, HDC hdcMem, int nWidth, int nHeight, UINT nIntervalTime = 10)
{
	int i, j;
	for (i = 0;i <= nHeight; i += 2) 
	{
		for (j = i; j > 0; j -= 2)
		{
			// 奇数行 从上往下
			BitBlt(hdc, 0, j - 1, nWidth, 1, hdcMem, 0, nHeight - (i - j - 1), SRCCOPY);
			// 偶数行 从下往上
			BitBlt(hdc, 0, nHeight - j, nWidth, 1, hdcMem,	0, i - j, SRCCOPY); 
		} 
		Sleep(nIntervalTime); 
	}
	BitBlt(hdc, 0, 0, nWidth, nHeight, hdcMem, 0, 0, SRCCOPY);
}

// 交错 - 垂直
//《Windows界面编程第九篇 位图显示特效 交错效果》
//http://blog.csdn.net/morewindows/article/details/8696720
void AnimateDraw_StaggeredVertical(HDC hdc, HDC hdcMem, int nWidth, int nHeight, UINT nIntervalTime = 10)
{
	int i, j;
	for (i = 0; i <= nWidth; i += 2) 
	{
		for (j = i; j > 0; j -= 2)
		{
			// 奇数列 从左往右
			BitBlt(hdc, j - 1, 0, 1, nHeight, hdcMem, nWidth - (i - j - 1), 0, SRCCOPY);
			// 偶数行 从右往左
			BitBlt(hdc, nWidth - j, 0, 1, nHeight, hdcMem, i - j, 0, SRCCOPY); 
		} 
		Sleep(nIntervalTime); 
	}
	BitBlt(hdc, 0, 0, nWidth, nHeight, hdcMem, 0, 0, SRCCOPY);
}


完整的程序在《Windows界面编程第十三篇位图显示特效合集》

http://blog.csdn.net/morewindows/article/details/8696730

下一篇《Windows界面编程第十篇位图显示特效百叶窗效果》将讲解百叶窗效果,地址在:http://blog.csdn.net/morewindows/article/details/8696722

 

转载请标明出处,原文地址:http://blog.csdn.net/morewindows/article/details/8696720

欢迎关注微博:http://weibo.com/MoreWindows

 

 

 

 

posted @ 2013-03-25 13:36  xinyuyuanm  阅读(238)  评论(0编辑  收藏  举报