zoukankan      html  css  js  c++  java
  • 图片旋转

    procedure TForm16.bmp_rotate(src,dst: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
      angle:=(angle/180)*pi;
      c1x:=src.Width div 2;
      c1y:=src.Height div 2;
      c2x:=dst.Width div 2;
      c2y:=dst.Height div 2;

      if c2x<c2y then
       n:=c2y
       else
       n:=c2x;

       dec(n);

       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:=src.Canvas.Pixels[c1x+p1x,c1y+p1y];
           c1:=src.canvas.Pixels[c1x-p1x,c1y-p1y];
           c2:=src.Canvas.Pixels[c1x+p1y,c1y-p1x];
           c3:=src.Canvas.Pixels[c1x-p1y,c1y+p1x];

           dst.canvas.Pixels[c2x+p2x,c2y+p2y]:=c0;
           dst.Canvas.Pixels[c2x-p2x,c2y-p2y]:=c1;
           dst.canvas.Pixels[c2x+p2y,c2y+-p2x]:=c2;
           dst.canvas.Pixels[c2x-p2y,c2y+p2x]:=c3;
           end;
           application.ProcessMessages;
           end;

    end;
    procedure TForm16.Button1Click(Sender: TObject);
    var
      RAngle:Extended;
    begin
      RAngle:=strToFloat(Edit1.Text);
      bmp_rotate(image1.Picture.Bitmap,image2.Picture.Bitmap,Rangle);
    end;

  • 相关阅读:
    PAT 甲级 1101 Quick Sort
    PAT 甲级 1038 Recover the Smallest Number
    #Leetcode# 112. Path Sum
    #Leetcode# 17. Letter Combinations of a Phone Number
    #Leetcode# 235. Lowest Common Ancestor of a Binary Search Tree
    C++结构体重构
    【NOIP2016提高A组模拟9.7】鼎纹
    快速幂总结
    【NOIP2013提高组】货车运输
    【NOIP2015提高组】运输计划
  • 原文地址:https://www.cnblogs.com/huking/p/1702711.html
Copyright © 2011-2022 走看看