怎么实现转场效果?(100分急购!!!fire119) (100分)

L

ljt119

Unregistered / Unconfirmed
GUEST, unregistred user!
Delphi中能不能实现向Authorware一样的转场效果?
___就像广场上的大屏幕一样
 
没用过Authorware,它的转场效果是个什么样的效果?
 
不同的画面
不同的出现效果.
 
是象窗口的上拉、下拉、淡入淡出这样的吗?
 
或窗口,或图像框中图像的效果,
或文本框中的文本效果,效果越多越好!
 
转场?是不是指360度全景图的效果???
如果YES,回答是——Delphi can do it !!!
 
不同的图片之间的转换效果!
 
老大用“淡入淡出”在已答问题中搜索一下,有十来个贴子说过这类问题了
 
以后先搜索一下,没有就换关键字,试试,
我记得有个控件包,有这个功能,很好用也很简单,只是,一下子找不到
(也许是分少,哈哈,跟你开玩笑的,搜一下,看看把,如果找不到,找我)
ispmaster@cnuninet.com
 

让图像旋转



***********************
---- Delphi中的Image构件可以显示位图,进一步,我们还可以用它完成位图旋转。

---- 把一个点绕原点旋转α角度后,新的坐标位置与原坐标位置的关系是:

X=x?cosα-y?sinα
Y= x?sinα+y?cosα
例如要把位图顺时针旋转90度,坐标变换公式为:X=-y Y=x

---- 把这一公式用到Image构件上,显示位图的主要问题是Image构件显示的位图只有一个象限, 并且x、y坐标也是互相颠倒的,为了解决这个问题,必须在Image构件上建立一个新的坐标原点。下面就举例说明。
---- 1. 新建一工程project1, 在form1上添加image1、 image2、 image3、image4,其 Autosize属性设为True, image1用来显示原图,image2、image3、image4分别用来显示旋转90度、180度和270度后的图像。双击image1,选定一幅bmp图。

---- 2. 添加Button1、Button2、Button3和Button4按钮,其caption属性分别为“原图”、 “旋转90度”、“旋转180度”、“旋转270度”。

---- 3. 编写“旋转90度”按钮的On Click事件。

procedure TForm1. Button2Click (Sender: TObject);
var
i,j:integer;
begin
//确定旋转后位图的大小
image2.Picture.Bitmap.Height:=image1.picture.width;
image2.Picture.Bitmap.Width:=image1.picture.height;
for i:=0 to image1.Height do
for j:=0 to image1.Width do
image2.canvas.Pixels[(-i+ image1.Height),
j]:=image1.canvas.Pixels[j,i];
end;


---- 4. 编写“旋转180度”按钮的On Click事件。
procedure TForm1.Button3Click(Sender: TObject);
var
i,j:integer;
begin
//确定旋转后位图的大小
image3.Picture.Bitmap.Height:=image1.picture.Height;
image3.Picture.Bitmap.Width:=image1.picture.Width;
for i:=0 to image1.Height do
for j:=0 to image1.Width do
image3.canvas.Pixels[(image1.Width
-j),(image1.Height-i)]:=image1.canvas.Pixels[j,i];
end;

---- 5. 编写“旋转270度” 按钮的On Click事件。代码和步骤3相似,只需要用image4 替换image2,然后用以下的语句替换步骤3 for循环中的原有的语句。
image4.canvas.Pixels[i,(image1.Width-j)]:=image1.canvas.Pixels[j,i];
-
 
快速简单地实现淡入淡出效果
    
在应用程序中引入图片淡入及淡出,可以让用户界面更加美观。
以前报刊杂志中介绍的常用方法有两种:一是自己写程序,诸个象素
进行混合渐变;二是使用DirectX,建立一个带Alpha通道的Surface。
第一种,效果可以自己控制,但比较麻烦,而且一般不容易生成硬件优化的代码;
第二种速度很快,却需要使用DirectX库。其实何必舍近求远呢?在
Windows的GDI中已经提供了一个很好的API――AlphaBlend让我们使用,
既保证速度又很简单,本文就详细介绍如何使用它。
  这里用Delphi 4.0讲解方法,因为在Delphi中声明和使用Windows API很方便。
在Delphi 4.0 Source目录下的Windows.pas中,已经有了AlphaBlend的声明,
但Delphi却把它认作是GDI32.dll提供的函数,其实微软把它放到了msimg32.dll
这个动态库中,因此直接使用AlphaBlend后,编译运行会产生一个引用错误,必须
自己来声明一个新函数,这里我们用AlphaBlendA来引用:(此问题在Delphi 6.0中已解决)
type // Delphi的声明段中加上以下一行

function AlphaBlendA(DestDC: HDC; TopDest, LeftDest, WidthDest, HeightDest: Integer;
SrcDC: HDC; TopSrc, LeftSrc, WidthSrc, HeightSrc: Integer;
BlendFunction: TBlendFunction): BOOL; stdcall; // API函数声明

implementation // Delphi的实现段中加上以下一行

function AlphaBlendA; external 'msimg32.dll' name 'AlphaBlend'; // 实现函数
其中DestDC参数是生成画面的Handle,在Delphi中一般是Canvas.Handle,TopDest,
LeftDest, WidthDest, HeightDest是生成画面的右上角坐标和长宽值;SrcDC, TopSrc,
LeftSrc, WidthSrc, HeightSrc表示原图的相关参数,因为AlphaBlend会自动处理缩放,
所以WidthDest, Height, LeftSrc, WidthSrc可以为不同值;DestBlendFunction是控制
Alpha混合的结构。
DestBlendFunction这个结构,是AlphaBlend的使用中最重要的参数,它的定义如下:
typedef struct _BLENDFUNCTION
{
BYTE BlendOp;
BYTE BlendFlags;
BYTE SourceConstantAlpha;
BYTE AlphaFormat;
}BLENDFUNCTION, *PBLENDFUNCTION, *LPBLENDFUNCTION;
BlendOP是混合方式,当前只有AC_SRC_OVER一种,即将SrcDC放置于DstDC之上,进行混合;
BlendFlags必须为零,为什么呢?M$没有告诉我们。
SourceConstantAlpha控制SrcDC画面的透明度,为0时,完全透明;为255时,完全不透明,
其间逐渐变化。
AlphaFormat表示SrcDC和DstDC的格式,一般不用指定。
为了避免动态生成的麻烦,我们直接放两个Image控件在Form上,Image1先调入一幅BMP图
片,Image2则设好大小即可。再放两个Button上去,Caption各设为“淡入”和“淡出”,
接下来,写按钮事件即淡入淡出效果处理:
procedure TForm1.Button1Click(Sender: TObject); // 淡入效果
var
sBlendFunction: BlendFunction; // 这是Alpha混合时需要的一个类型参数
i: byte; // 循环变量
begin
Button1.Enabled := False; // 暂停“淡入”按钮输入
with sBlendFunction do // 设置初值
begin
BlendOp := AC_SRC_OVER; // 目前唯一支持的一种混合方式
BlendFlags := 0; // 必须为零
AlphaFormat := 0 // 缺省
end;
for i := 0 to 51 do // 共有51帧
begin
sBlendFunction.SourceConstantAlpha := i * 5; // 从全透明到不透明,每次渐变5级
AlphaBlendA(Image2.Canvas.Handle,0,0,
Image2.Width,Image2.Height,Form1.Canvas.Handle,
Image1.Top,Image1.Left, Image1.Width,Image1.Height,sBlendFunction); // Alpha混合处理
sleep(10); // 延时10毫秒,适当的延时可让效果看起来更逼真
Image2.Refresh // 一定要实时刷新Image2,才能看出变化
end;
Button2.Enabled := True // 允许“淡出”按钮的输入
end;
而在淡出效果(即Button2的处理)中,只要将背景底色中的一块作为原图即可:
AlphaBlendA(Image2.Canvas.Handle,0,0,Image2.Width,Image2.Height,Form1.Canvas.Handle,290,250,20,20,sBlendFunction);// (290,250,310,270)区域为底色
以上程序在Windows 98,Inprise Delphi 4.0 Update Pack 3下运行通过。
利用AlphaBlend还可以产生其它图象效果,比如将SourceConstantAlpha适当居中,
能象PhotoShop一样出现“浮雕”的效果等。
在msimg32.dll中,除了AlphaBlend,还有TransparentBlt和GradientFill等很有用
的API:TransparentBlt可以快速处理16色和256色的透明贴图(AlphaBlend可以处理
32位色);GradientFill则能够借助硬件加速,产生颜色渐变的三角形或矩形,利用
上它们,将会让你编写的程序更加吸引人。
 
Delphi中的图形显示技巧
概 述
---- 目 前 在 许 多 学 习 软 件、 游 戏 光 盘 中, 经 常 会 看 到 各 种 图 形 显 示 技 巧, 凭 着 图 形 的 移 动、 交 错、 雨 滴 状、 百 页 窗、 积 木 堆 叠 等 显 现 方 式, 使 画 面 变 得 更 为 生 动 活 泼, 更 能 吸 引 观 众。 本 文 将 探 讨 如 何 在Delphi 中 实 现 各 种 图 形 显 示 技 巧。
基 本 原 理
---- 在Delphi 中, 实 现 一 副 图 象 的 显 示 是 非 常 简 单 的, 只 要 在Form 中 定 义 一 个TImage 组 件, 设 置 其picture 属 性, 然 后 选 择 任 何 有 效 的.ICO、.BMP、.EMF 或.WMF 文 件, 进 行Load, 所 选 文 件 就 显 示 在TImage 组 件 中 了。 但 这 只 是 直 接 将 图 形 显 示 在 窗 体 中, 毫 无 技 巧 可 言。 为 了 使 图 形 显 示 具 有 别 具 一 格 的 效 果, 可 以 按 下 列 步 骤 实 现:
---- 1、 定 义 一 个TImage 组 件, 把 要 显 示 的 图 形 先 装 入 到TImage 组 件 中, 也 就 是 说, 把 图 形 内 容 从 磁 盘 载 入 内 存 中, 做 为 图 形 缓 存。
---- 2、 创 建 一 新 的 位 图 对 象, 其 尺 寸 跟TImage 组 件 中 的 图 形 一 样。
---- 3、 利 用 画 布(Canvas) 的CopyRect 功 能( 将 一 个 画 布 的 矩 形 区 域 拷 贝 到 另 一 个 画 布 的 矩 形 区 域), 使 用 技 巧, 动 态 形 成 位 图 文 件 内 容, 然 后 在 窗 体 中 显 示 位 图。
实 现 方 法
---- 下 面 介 绍 各 种 图 形 显 示 技 巧:
---- 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-2;
end;
form1.Canvas.Draw(120,100,newbmp);
i:=i+2;
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;

结 束 语
---- 上 述 图 形 显 示 效 果 均 已 上 机 通 过, 软 件 环 境Delphi 3.0, 硬 件 环 境Pentium 100M 兼 容 机。 使 用 效 果 很 好。
---- 参 考 文 献:
---- 1. 《Delphi3.0 User's Guide》 Borland International Inc.
---- 2. 《Delphi3.0 自 学 通》 机 械 工 业 出 版 社

 
很简单的呀,下面代码,速度比较慢 。论坛上有更快的你去找找。
procedure TForm1.Button2Click(Sender: TObject); //上下推拉
var
newbmp: TBitmap;
i,bmpheight,bmpwidth:integer;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=Form2.image1.Width;
newbmp.Height:=Form2.image1.Height;
bmpheight:=Form2.image1.Height;
bmpwidth:=Form2.image1.Width;
for i:=0 to bmpheight do begin
newbmp.Canvas.CopyRect(Rect(0,bmpheight-i,bmpwidth,bmpheight),
Form2.image1.Canvas,Rect(0,0,bmpwidth,i));
Form1.Canvas.Draw(50,25,newbmp);
end;
newbmp.free;
end;

procedure TForm1.Button3Click(Sender: TObject);//上下交错
var
newbmp:TBitmap;
i,j,bmpheight,bmpwidth:integer;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=Form2.image1.Width;
newbmp.Height:=Form2.image1.Height;
bmpheight:=Form2.image1.Height;
bmpwidth:=Form2.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),Form2.image1.Canvas,
Rect(0,bmpheight-i+j-1,bmpwidth,bmpheight-i+j));
newbmp.Canvas.CopyRect(Rect
(0,bmpheight-j,bmpwidth,bmpheight-j+1),
Form2.image1.Canvas,Rect(0,i-j,bmpwidth,i-j+1));
j:=j-2;
end;
form1.Canvas.Draw(50,25,newbmp);
i:=i+2;
end;
newbmp.free;
end;

procedure TForm1.Button4Click(Sender: TObject);//水平交错
var
newbmp:TBitmap;
i,j,bmpheight,bmpwidth:integer;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=Form2.image1.Width;
newbmp.Height:=Form2.image1.Height;
bmpheight:=Form2.image1.Height;
bmpwidth:=Form2.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),Form2.image1.Canvas,
Rect(bmpwidth-i+j-1,0,bmpwidth-i+j,bmpheight));
newbmp.Canvas.CopyRect(Rect(bmpwidth-j,0,
bmpwidth-j+1,bmpheight),Form2.image1.Canvas,
Rect(i-j,0,i-j+1,bmpheight));
j:=j-2;
end;
form1.Canvas.Draw(50,25,newbmp);
i:=i+2;
end;
newbmp.free;
end;

procedure TForm1.Button6Click(Sender: TObject); //百叶窗效果
var
newbmp:TBitmap;
i,j,bmpheight,bmpwidth:integer;
xgroup,xcount:integer;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=Form2.image1.Width;
newbmp.Height:=Form2.image1.Height;
bmpheight:=Form2.image1.Height;
bmpwidth:=Form2.image1.Width;
xgroup:=16;
xcount:=bmpheight div xgroup;
for i:=0 to xcount do begin
for j:=0 to xgroup do begin
newbmp.Canvas.CopyRect(Rect(0,xcount*j+i-1,bmpwidth,xcount*j+i),
Form2.image1.Canvas,Rect(0,xcount*j+i-1,bmpwidth,xcount*j+i));
form1.Canvas.Draw(50,25,newbmp);

end;
end;
newbmp.Free;
end;

渐慢的速太慢了,不好意思贴了!

 
很多书上都有[:)]
 
谢谢大家!
 
接受答案了.
 
顶部