delphi2007 教程

delphi2007 教程

首页 新随笔 联系 聚合 管理
  1013 Posts :: 0 Stories :: 28 Comments :: 0 Trackbacks
图片翻转时,一变成二,怎么先擦除掉之前那个图 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiMultimedia/html/delphi_20061026103637202.html
如题,我要把图片翻转,但是翻过来后原先的图还在,变成了原图跟新图叠在一起了,代码如下  
   
   
      for   i:=   0   to   Image1.width   do  
      begin  
          with   rect1   do  
          begin  
              left:=i;  
              top:=0;  
              right:=i+1;  
              bottom:=Image1.height;  
          end;  
          with   rect2   do  
          begin  
              left:=(Image1.width)-i-1;  
              top:=0;  
              right:=(Image1.width)-i;  
              bottom:=Image1.height;  
          end;  
          Image1.canvas.copyrect(rect2,Image1.canvas,rect1);  
      end;

这个问题应该不是太难吧~~~   再顶顶

procedure   Tform1.bmp_rotate(Srcbmp,   DestBmp:   Tbitmap;   angle:   extended);  
  var  
      c1x,   c1y,   c2x,   c2y:   integer;  
      p1x,   p1y,   p2x,   p2y:   integer;  
      radius,   n:   integer;  
      alpha:   extended;  
      c0,   c1,   c2,   c3:   tcolor;  
  begin  
      if   SrcBmp.Width   >   SrcBmp.Height   then  
      begin  
          DestBmp.width   :=   SrcBmp.Width;  
          DestBmp.height   :=   SrcBmp.Width;  
      end  
      else  
          DestBmp.Width   :=   SrcBmp.Height;  
      DestBmp.Height   :=   SrcBmp.Height;  
      //将角度转换为PI值  
      angle   :=   (angle   /   180)   *   pi;  
      //   计算中心点,你可以修改它  
      c1x   :=   SrcBmp.width   div   2;  
      c1y   :=   SrcBmp.height   div   2;  
      c2x   :=   DestBmp.width   div   2;  
      c2y   :=   DestBmp.height   div   2;  
      //   步骤数值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   :=   SrcBmp.canvas.pixels[c1x   +   p1x,   c1y   +   p1y];  
              c1   :=   SrcBmp.canvas.pixels[c1x   -   p1x,   c1y   -   p1y];  
              c2   :=   SrcBmp.canvas.pixels[c1x   +   p1y,   c1y   -   p1x];  
              c3   :=   SrcBmp.canvas.pixels[c1x   -   p1y,   c1y   +   p1x];  
   
              DestBmp.Canvas.pixels[c2x   +   p2x,   c2y   +   p2y]   :=   c0;  
              DestBmp.canvas.pixels[c2x   -   p2x,   c2y   -   p2y]   :=   c1;  
              DestBmp.canvas.pixels[c2x   +   p2y,   c2y   -   p2x]   :=   c2;  
              DestBmp.canvas.pixels[c2x   -   p2y,   c2y   +   p2x]   :=   c3;  
          end;  
          application.processmessages  
      end;  
  end;  
   
   
  procedure   TForm1.Button1Click(Sender:   TObject);  
  var  
      newbmp:   TBitmap;  
      Bitmap:   TBitmap;  
      angle:   integer;  
  begin  
      Bitmap   :=   TBitmap.Create;  
  newbmp:=   TBitmap.Create;  
      screen.Cursor   :=   crhourglass;  
      newbmp.Assign(image1.Picture.Bitmap);  
   
      angle   :=   strtoint(inputbox('旋转位图',   '请输入旋转角度',   '90'));  
      Bmp_Rotate(newbmp,   bitmap,   angle);  
      image1.picture.Bitmap.Assign(bitmap);  
      image1.Left   :=   (self.Width   div   2)   -   (bitmap.Width   div   2);  
      image1.Top   :=   (self.Height   div   2)   -   (bitmap.Height   div   2);  
      screen.Cursor   :=   crdefault;  
      newbmp.Free;  
      Bitmap.Free;  
  end;  
 

posted on 2008-12-19 10:02 delphi2007 阅读(147) 评论(0)  编辑 收藏 引用
只有注册用户登录后才能发表评论。