图形特效 四

                             旋转图像特效
   输入参数:
     Image          要进行旋转特效的TImage
     Angle          旋转的角度(以度为单位,例如90表示旋转90度)
     SleepTime      特效的快慢控制
}
procedure Img_Rotate(Image:TImage;Angle:Extended;SleepTime:Word);
var
c1x,c1y,c2x,c2y:Integer;
p1x,p1y,p2x,p2y:Integer;
radius,n:Integer;
alpha:Extended;
c0,c1,c2,c3:TColor;
OldBmp:TBitmap;
begin
OldBmp:=TBitmap.Create;
try
 OldBmp.Assign(Image.Picture.Graphic);
 Image.Picture:=nil;
 angle:=(Angle/180)*PI; //将角度转换为PI值
 // 计算中心点
 c1x:=OldBmp.Width div 2;
 c1y:=OldBmp.Height div 2;
 c2x:=c1x;
 c2y:=c1y;
 // 步骤数值number
 if c2x < c2y then n:=c2y
 else n:=c2x;
 Dec(n,1);
 // 开始旋转
 for p2x:=0 to n do
 begin
  for p2y:=0 to n do
  begin
   if p2x=0 then alpha:=PI/2
   else alpha:=ArcTan2(p2y,p2x);
   radius:=Round(Sqrt((p2x*p2x)+(p2y*p2y)));
   p1x:=Round(radius*Cos(angle+alpha));
   p1y:=Round(radius*Sin(angle+alpha));

   c0:=OldBmp.Canvas.Pixels[c1x+p1x,c1y+p1y];
   c1:=OldBmp.Canvas.Pixels[c1x-p1x,c1y-p1y];
   c2:=OldBmp.Canvas.Pixels[c1x+p1y,c1y-p1x];
   c3:=OldBmp.Canvas.Pixels[c1x-p1y,c1y+p1x];

   Image.Canvas.Pixels[c2x+p2x,c2y+p2y]:=c0;
   Image.Canvas.Pixels[c2x-p2x,c2y-p2y]:=c1;
   Image.Canvas.Pixels[c2x+p2y,c2y-p2x]:=c2;
   Image.Canvas.Pixels[c2x-p2y,c2y+p2x]:=c3;
   Image.Refresh;
   Sleep(SleepTime);
  end;
 end;
finally
 OldBmp.Free;
end;
end;



{ 扇形图像特效
   输入参数:
     Image          要进行扇形特效的TImage
     SleepTime      特效的快慢控制
     bgColor        背景色
}
procedure Img_Sector(Image:TImage;SleepTime:Word;bgColor:TColor);
var
 i,a,b,x0,y0,x,y:Integer;
 d:Extended;
 OldBmp:TBitmap;
 ARect,r:TRect;
begin
 OldBmp:=TBitmap.Create;
 try
  OldBmp.Assign(Image.Picture.Graphic);
  Image.Picture:=nil;
  ARect:=Rect(0,0,OldBmp.Width,OldBmp.Height);
  a:=(Arect.Right-Arect.Left ) div 2;  //椭圆横轴
  b:=(Arect.Bottom-Arect.Top ) div 2;  //椭圆纵轴
  x0:=Arect.Left+a;                    //椭圆中心X
  y0:=Arect.Top+b;                     //椭圆中心Y
  r.Left:=0;
  r.Top:=0;
  r.Right:=2*a;
  r.Bottom:=2*b;
  Image.Canvas.Brush.Color:=bgColor;   //涂背景色
  Image.Canvas.FillRect(r);
  Image.Canvas.Brush.Color:=clWhite;
  for i:=1 to 36 do
  begin
   d:=i/18*PI;
   x:=x0+Round(a*Cos(d));
   y:=y0-Round(b*Sin(d));
   //用白色画扇形
   if (i=36) then Image.Canvas.Ellipse(x0-a,y0-b,x0+a,y0+b)
   else Image.Canvas.Pie(x0-a,y0-b,x0+a,y0+b,x0+a,y0,x,y);
   Image.Canvas.CopyMode:=cmSrcAnd;
   //显示位图的扇形区域
   Image.Canvas.CopyRect(r,OldBmp.Canvas,r);
   Image.Refresh;
   Sleep(SleepTime);
 end;
finally
 OldBmp.Free;
end;
end;


{ 淡出图像特效: *****在24位或者32位位图格式下,工作正常******
   输入参数:
     Image       要进行淡出特效的TImage
     SleepTime   特效的快慢控制
}
procedure Img_FadeOut(Image:TImage;SleepTime:Word);
var
BytesPorScan:Integer;
w,h:integer;
p:pByteArray;
counter:integer;
begin
BytesPorScan:=Abs(Integer(Image.Picture.Bitmap.ScanLine[1])-
                  Integer(Image.Picture.Bitmap.ScanLine[0]));

for counter:=1 to 256 do
begin
 for h:=0 to Image.Picture.Bitmap.Height-1 do
 begin
  P:=Image.Picture.Bitmap.ScanLine[h];
  for w:=0 to BytesPorScan-1 do
   if P^[w]>0 then P^[w]:=P^[w]-1;
 end;
 Image.Refresh;
 Sleep(SleepTime);
end;
end;


{ 淡入图像特效: *****在24位或者32位位图格式下,工作正常******
   输入参数:
     Image       要进行淡入特效的TImage
     SleepTime   特效的快慢控制
}
procedure Img_FadeIn(Image:TImage;SleepTime:Word);
var
BytesPorScan:Integer;
w,h:integer;
p1,p0:pByteArray;
counter:Integer;
SrcBmp:TBitmap;
begin
SrcBmp:=TBitmap.Create;
try
 SrcBmp.Assign(Image.Picture.Bitmap);
 Image.Picture.Bitmap.Canvas.Brush.Color:=clBlack;
 Image.Picture.Bitmap.Canvas.FillRect(Rect(0,0,SrcBmp.Width,SrcBmp.Height));
 Image.Refresh;
 BytesPorScan:=Abs(Integer(SrcBmp.ScanLine[1])-Integer(SrcBmp.ScanLine[0]));

 for counter:=1 to 256 do
 begin
  for h:=0 to SrcBmp.Height-1 do
  begin
   p0:=SrcBmp.ScanLine[h];
   p1:=Image.Picture.Bitmap.ScanLine[h];
   for w:=0 to BytesPorScan-1 do
    if p1^[w]<p0^[w] then p1^[w]:=p1^[w]+1;
  end;
  Image.Refresh;
  Sleep(SleepTime);
 end;
finally
 SrcBmp.Free;
end;
end;


const
{镜像类型常数}
mirrorHorizontal=1;  //水平镜像
mirrorVertical=2;    //垂直镜像

{水平镜像显示方式常数}
showRightToLeft=1;   //从右到左
showLeftToRight=2;   //从左到右

{垂直镜像显示方式常数}
showBottomToTop=1;   //从下到上
showTopToBottom=2;   //从上到下



{ 镜像图像
   输入参数:
     Image          要进行镜像的TImage
     MirrorStyle    镜像类型
     ShowMode       显示方式
     SleepTime      特效的快慢控制
}
procedure Img_Mirror(Image:TImage;MirrorStyle,ShowMode,SleepTime:Word);
var
OldBmp:TBItmap;
i,BmpWidth,BmpHeight:Integer;
begin
OldBmp:=TBitmap.Create;
try
 OldBmp.Assign(Image.Picture.Graphic);
 Image.Picture:=nil;
 BmpWidth:=OldBmp.Width;
 BmpHeight:=OldBmp.Height;
 case MirrorStyle of
  mirrorHorizontal :begin
                     for i:=0 to BmpWidth  do
                     begin
                      if ShowMode=showLeftToRight then
                       Image.Canvas.CopyRect(Rect(i,0,i+1,BmpHeight),
                                             OldBmp.Canvas,
                                             Rect(BmpWidth-i-1,0,
                                                  BmpWidth-i,BmpHeight))
                      else
                       Image.Canvas.CopyRect(Rect(BmpWidth-i-1,0,
                                                  BmpWidth-i,BmpHeight),
                                             OldBmp.Canvas,
                                             Rect(i,0,i+1,BmpHeight));
                      Image.Refresh;
                      Sleep(SleepTime);
                     end;
                    end;
  mirrorVertical :begin
                   for i:=0 to BmpHeight  do
                   begin
                    if ShowMode=showTopToBottom then
                     Image.Canvas.CopyRect(Rect(0,i,BmpWidth,i+1),
                                           OldBmp.Canvas,
                                           Rect(0,BmpHeight-i-1,
                                                BmpWidth,BmpHeight-i))
                    else
                     Image.Canvas.CopyRect(Rect(0,BmpHeight-i-1,
                                                BmpWidth,BmpHeight-i),
                                           OldBmp.Canvas,
                                           Rect(0,i,BmpWidth,i+1));
                    Image.Refresh;
                    Sleep(SleepTime);
                   end;
                  end;
 end;
finally
 OldBmp.Free;
end;
end; 

                                

查看回复

最新教程