打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Delphi位图任意角度旋转

Delphi位图任意角度旋转

时间:2011-6-2来源:yang 作者: peng点击: 15次

//***********************************************************
//功能:任意角度旋转
//参数:Srcbmp:源位图 DestBmp:目标位图 ;angle旋转角度
//返回值:无
class procedure TGraphicUtil.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;

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
安卓实现个性彩色好看的二维码
delphi实现.bmp位图旋转90度。急求!!!
Delphi基本图像处理代码
如何量化一张图片的色彩关系?
实例讲解利用HTML5 Canvas API操作图形旋转的方法
jquery rotate.js
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服