中华网校

系列网站: 中华网校 | www.网校.com | 3D模型 | 中华网校教育

电脑网校 | 业界新闻 | 职业网校 | 网校宝典 | 软件下载 | 网校论坛 | 网校联盟

电脑入门 | 网页设计 | 网络编程 | 图形图象 | 三维空间 | 多媒体 | 程序语言 | 操作系统 | 系统专题 | 办公应用 | 软件宝典 | 硬件天下 | 

 

您的位置:首页 >> 程序语言 >> VC/VC.NET >> 新闻正文

用VC实现图象渐显和渐隐  

作者:_  时间:2001-10-12 14:42:59  来自:中华网校  责任编辑:  阅读次数:

if (palettecolors[i].pegreen + 1 <

palettecolors0[i].pegreen)

{

palettecolors[i].pegreen++;

bgreenzero = false;

}

else

bgreenzero = true;

if (palettecolors[i].peblue + ndeta <

palettecolors0[i].peblue)

{

palettecolors[i].peblue += ndeta;

bbluezero = false;

}

else if (palettecolors[i].peblue +1 <

palettecolors0[i].peblue)

{

palettecolors[i].peblue++;

bbluezero = false;

}

else

bbluezero = true;

}

// 直到恢复原始值结束

bdone = bredzero && bgreenzero && bbluezero;

// 使系统改变调色板

ppal->animatepalette(0, ntotalcolors, palettecolors);

}

::translatemessage(&msg);

::dispatchmessage(&msg);

}

}

::releasecapture();

pwnd->killtimer(0x100);

// 恢复原始调色板

ppal->setpaletteentries(0, ntotalcolors, palettecolors0);

ppal->animatepalette(0, ntotalcolors, palettecolors0);

}

四、渐隐

渐隐就是将显示颜色由图象各象素的颜色逐渐变化为黑色(rgb(0, 0, 0))的过程,即定时调用cpalette::animatepalette,每次将各逻辑表项的pered、pegreen、peblue值减小一个变化量,直到它们都为0。

下面的函数fadeout通过对调色板颜色表项中的各颜色分量值进行递减,直到所有颜色值都变成0(即黑色)来实现渐隐。

// 图象渐隐效果

// 参数:

// pwnd – 显示图象的窗口

// ppal – 调色板指针

// ndeta – 各颜色分量的减小量

// utimeout – 时间的变化量

void fadeout(cwnd *pwnd, cpalette *ppal, int ndeta, uint utimeout)

{

// 保留原来的调色板颜色表项

int ntotalcolors = ppal->getentrycount();

paletteentry palettecolors0[256];

ppal->getpaletteentries(0, ntotalcolors, palettecolors0);

// 设置时间码

pwnd->settimer(0x100, utimeout, null);

// 开始渐隐

pwnd->setcapture();

bool bdone = false;

msg msg;

while (! bdone)

{

if (::peekmessage(&msg, null, 0, 0, pm_remove))

{

if (msg.message == wm_timer && msg.wparam == 0x100)

{

cclientdc dc(pwnd);

cpalette *poldpal = dc.selectpalette(ppal, false);

dc.realizepalette();

paletteentry palettecolors[256];

ppal->getpaletteentries(0, ntotalcolors, palettecolors);

bool bredzero=false;

bool bgreenzero=false;

bool bbluezero=false;

// 递减颜色分量

for (int i=0; i
{

if (palettecolors[i].pered > ndeta)

{

palettecolors[i].pered -= ndeta;

bredzero = false;

}

else if (palettecolors[i].pered > 1)

{

palettecolors[i].pered--;

bredzero = false;

}

else

bredzero = true;

if (palettecolors[i].pegreen > ndeta)

{

palettecolors[i].pegreen -= ndeta;

bgreenzero = false;

}

else if (palettecolors[i].pegreen > 1)

{

palettecolors[i].pegreen--;

bgreenzero = false;

}

else

bgreenzero = true;

if (palettecolors[i].peblue > ndeta)

{

palettecolors[i].peblue -= ndeta;

bbluezero = false;

}

else if (palettecolors[i].peblue > 1)

{

palettecolors[i].peblue--;

bbluezero = false;

}

else

bbluezero = true;

}

// 如所有颜色分量都为0,则结束渐隐

bdone = bredzero && bgreenzero && bbluezero;

// 使系统改变调色板

ppal->animatepalette(0, ntotalcolors, palettecolors);

}

::translatemessage(&msg);

::dispatchmessage(&msg);

}

}

::releasecapture();

pwnd->killtimer(0x100);

// 恢复原始调色板

ppal->setpaletteentries(0, ntotalcolors, palettecolors0);

ppal->animatepalette(0, ntotalcolors, palettecolors0);

   用VC实现图象渐显和渐隐   共有2页  1  2 页

相关文章 最新文章 推荐文章
用VC实现图象渐显和渐隐

  中华网校依法保护知识产权,如果我们的文章有涉及或侵犯您的有关权益,请即时与我们 联系, 注明网址及文章,我们会即时处理或删除,感谢您的合作!中华网校email
  中华网校由广州市中六电脑城智锐计算机专业培训学院及中华网校技术中心提供网络支持未经本站许可任何个人网站、书刊报社一律不得私自复制,转载本站内容!

关于中华网校 | 广告服务 | 版权声明 | 投稿指南 | 网站合作 | 友情链接 | 网站地图

 

版权所有 中华网校 & 智锐网校 1999-2004 COPYRIGHT (C) 1999-2004 www.ZhiRui.com ALL RIGHTS RESERVED

 
/**/