中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > Delphi > 综合文章
Delphi编程的图形显示技巧
作者:未知 时间:2005-08-07 20:59 出处:编程爱好者网站 责编:chinaitpower
              摘要:Delphi编程的图形显示技巧
发软件时经常需要加入各种图形的特效显示效果,这样可以使画面变得更为生动活泼,增加软件的趣味性,使软件更加受欢迎。本文将探讨如何在Delphi编程中实现移动、交错、瀑布状、百叶窗和积木堆叠等各种图形特效显示效果。

基本原理
在Delphi中,实现图像的显示是非常简单的,我们只要在Form中定义一个TImage组件,设置其picture属性,然后选择任何有效的.ICO、.BMP、.EMF或.WMF文件,进行载入,所选文件就会显示在TImage组件中。但这只是直接将图形显示在窗体中,毫无技巧可言。为了使图形显示具有特殊效果,我们可以按下列步骤实现:

1.定义一个TImage组件,把要显示的图形先装入到TImage组件中,作为图形缓存;

2.创建一新的位图对象,其尺寸跟TImage组件中的图形一样;

3.利用画布(Canvas)的CopyRect功能(将一个画布的矩形区域拷贝到另一个画布的矩形区域),使用技巧,动态形成位图文件内容,然后在窗体中显示位图。

实现方法
首先在窗体上定义一个Image控件Image1,载入一幅图像(注意将其AutoSize设为True,Visible设为False),再定义6个按钮控件,分别设置Caption为“推拉”、“垂直交错”、“水平交错”、“瀑布”、“百叶窗”、“积木”,图形特效的编程原理和按钮的Click程序分别如下。

1.推拉效果

将要显示的图形由上、下、左、右方向拉进屏幕内显示,同时将屏幕上原来的旧图覆盖掉,此种效果可分为四种:上拉、下拉、左拉和右拉,但原理都差不多,笔者程序以上拉效果为例。

>原理:

首先将放在缓存中图形的第一条水平线,搬移至要显示的位图的最后一条,接着再将缓存中图形的前两条水平线,按顺序搬移至要显示位图的最后两条水平线,然后搬移前三条、前四条……直到全部图形数据搬完为止。在搬移的过程中即可看到显示的位图由下而上浮起,而达到上拉的效果。

>程序算法如下:

procedure TForm1.Button1Click(Sender: TObject);
var
newbmp: TBitmap;
i,bmpheight,bmpwidth:integer;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=image1.Width;
newbmp.Height:=image1.Height;
bmpheight:=image1.Height;
bmpwidth:=image1.Width;
for i:=0 to bmpheight do
begin
newbmp.Canvas.CopyRect(Rect(0,bmpheight-i,bmpwidth,bmpheight),image1.Canvas,Rect(0,0,bmpwidth,i));
form1.Canvas.Draw(120,100,newbmp);
end;
newbmp.free;
end;


2.垂直交错效果

>原理:

将要显示的图形分成两部分,奇数条扫描线由上往下搬移,偶数条扫描线的部分则由下往上搬移,而且两者同时进行。从屏幕上便可看到分别由上下两端出现的较淡图形向屏幕中央移动,直到完全清楚为止。

>程序算法如下:

procedure TForm1.Button4Click(Sender: TObject);
var
newbmp:TBitmap;
i,j,bmpheight,bmpwidth:integer;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=image1.Width;
newbmp.Height:=image1.Height;
bmpheight:=image1.Height;
bmpwidth:=image1.Width;
i:=0;
while i<=bmpheight do
begin
j:=i;
while j >0 do
begin
newbmp.Canvas.CopyRect(Rect(0,j-1,bmpwidth,j),image1.Canvas,Rect(0,bmpheight-i+j-1,bmpwidth,bmpheight-i+j));
newbmp.Canvas.CopyRect(Rect(0,bmpheight-j,bmpwidth,bmpheight-j+1), image1.Canvas,Rect(0,i-j,bmpwidth,i-j+1));
j:=j-1;
end;
form1.Canvas.Draw(120,100,newbmp);
i:=i+1;
end;
newbmp.free;
end;


3.水平交错效果

>原理:

同垂直交错效果原理一样,只是将分成两组后的图形分别由左右两端移进屏幕。

>程序算法如下:

procedure TForm1.Button5Click(Sender: TObject);
var
newbmp:TBitmap;
i,j,bmpheight,bmpwidth:integer;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=image1.Width;
newbmp.Height:=image1.Height;
bmpheight:=image1.Height;
bmpwidth:=image1.Width;
i:=0;
while i<=bmpwidth do
begin
j:=i;
while j>0 do
begin
newbmp.Canvas.CopyRect(Rect(j-1,0,j,bmpheight), image1.Canvas, Rect(bmpwidth-i+j-1,0,bmpwidth-i+j,bmpheight));
newbmp.Canvas.CopyRect(Rect(bmpwidth-j,0,bmpwidth-j+1,bmpheight), image1.Canvas, Rect(i-j,0,i-j+1,bmpheight));
j:=j-2;
end;
form1.Canvas.Draw(120,100,newbmp);
i:=i+2;
end;
newbmp.free;
end;


4.瀑布效果

>原理:

将缓存中图形的最后一条扫描线,按顺序搬移到可视位图的第一条到最后一条扫描线,让此条扫描线在屏幕上留下它的轨迹。接着再把缓存图形的倒数第二条扫描线,依序搬移到可视位图的第一条到倒数第二条扫描线。其余的扫描线依此类推。

>程序算法如下:

procedure TForm1.Button3Click(Sender: TObject);
var
newbmp:TBitmap;
i,j,bmpheight,bmpwidth:integer;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=image1.Width;
newbmp.Height:=image1.Height;
bmpheight:=image1.Height;
bmpwidth:=image1.Width;
for i:=bmpheight downto 1 do
for j:=1 to i do
begin
newbmp.Canvas.CopyRect(Rect(0,j-1,bmpwidth,j),image1.Canvas, Rect(0,i-1,bmpwidth,i));
form1.Canvas.Draw(120,100,newbmp);
end;
newbmp.free;
end;


5.百叶窗效果

>原理:

将放在缓存中图形的数据分成若干组,然后依次从第一组到最后一组搬移,第一次每组各搬移第一条扫描线到可视位图的相应位置,第二次搬移第二条扫描线,接着搬移第三条、第四条扫描线。

>程序算法如下:

procedure TForm1.Button6Click(Sender: TObject);
var
newbmp:TBitmap;
i,j,bmpheight,bmpwidth:integer;
xgroup,xcount:integer;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=image1.Width;
newbmp.Height:=image1.Height;
bmpheight:=image1.Height;
bmpwidth:=image1.Width;
xgroup:=16;
xcount:=bmpheight div xgroup;
for i:=0 to xcount do
for j:=0 to xgroup do
begin
newbmp.Canvas.CopyRect(Rect(0,xcountj+i-1,bmpwidth,xcountj+i), image1.Canvas, Rect(0,xcountj+i-1,bmpwidth,xcountj+i));
form1.Canvas.Draw(120,100,newbmp);
end;
newbmp.Free;
end;


6.积木效果

>原理:

是瀑布效果的一种变化,不同之处在于,积木效果每次搬移的是一块图形(组),而不只是一根扫描线。

>程序算法如下:

procedure TForm1.Button7Click(Sender: TObject);
var
newbmp:TBitmap;
i,j,bmpheight,bmpwidth:integer;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=image1.Width;
newbmp.Height:=image1.Height;
bmpheight:=image1.Height;
bmpwidth:=image1.Width;
i:=bmpheight;
while i>0 do
begin
for j:=10 to i do
begin
newbmp.Canvas.CopyRect(Rect(0,j-10,bmpwidth,j), image1.Canvas, Rect(0,i-10,bmpwidth,i));
form1.Canvas.Draw(120,100,newbmp);
end;
i:=i-10;
end;
newbmp.free;
end;


上述图形特效显示效果在Windows 98、Delphi 4.0下运行通过。当然图形效果还有许多,读者只要明白其中原理,就可以很容易设计并演示其他效果。 

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有