C# 实现图片旋转的代码 张宇轩

这段代码展示了如何使用C#进行图片旋转操作,以逆时针方向进行。通过输入旋转角度,利用数学公式计算新的图像尺寸,并进行高质量的图像平滑处理,最后实现360度范围内的任意角度旋转。
摘要由CSDN通过智能技术生成

#region 图片旋转函数
/// <summary>
/// 以逆时针为方向对图像进行旋转
/// </summary>
/// <param name="b">位图流</param>
/// <param name="angle">旋转角度[0,360](前台给的)</param>
/// <returns></returns>
public Bitmap Rotate(Bitmap b, int angle)
{
angle = angle % 360; //弧度转换
double radian = angle * Math.PI / 180.0;
double cos = Math.Cos(radian);
double sin = Math.Sin(radian);
//原图的宽和高
int w = b.Width;
int h = b.Height;
int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin)));
int H = (int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos)));
//目标位图
Bitmap dsImage = new Bitmap(W, H);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
g.SmoothingM

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值