大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> 程序开发 -> Delphi编程的图形显示技巧

Delphi编程的图形显示技巧

时间: 2021-07-31 作者:daque

发软硬件时常常须要介入百般图形的殊效表露功效,如许不妨使画面变得更为灵巧绚烂,减少软硬件的风趣性,使软硬件越发受欢送。正文将商量怎样在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 © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.