delphi BMP图片旋转

{
关键字=BMP旋转
采集软件=MKM - 我的知识管理
采集日期=2023-11-23 14:33:47
数字签名=D627E629E0F6C323AC9D5C5FC0A65320
}

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Vcl.Imaging.jpeg;

uses pngimage, Math, GraphUtil;

procedure TForm1.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
{BMP旋转 }
// 将角度转换为PI值
angle := (angle / 180) * pi;
// 计算中心点,你可以修改它
c1x := src.Width div 2;
c1y := src.Height div 2;
c2x := dst.Width div 2;
c2y := dst.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 := 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;

  • 7
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

欧色

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值