日期:2014-05-18  浏览次数:20917 次

C# 图片旋转
先说明,论坛上这个方法我已经看多了
  /// <summary>
  /// 旋转
  /// </summary>
  /// <param name="b"></param>
  /// <param name="angle"></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.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
  //计算偏移量
  Point Offset = new Point((W - w) / 2, (H - h) / 2);
  //构造图像显示区域:让图像的中心与窗口的中心点一致
  Rectangle rect = new Rectangle(0, 0, W, H);
  Point center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
  g.TranslateTransform(center.X, center.Y);
  g.RotateTransform(360 - angle);
  //恢复图像在水平和垂直方向的平移
  g.TranslateTransform(-center.X, -center.Y);
  g.DrawImage(b, rect);
  //重至绘图的所有变换
  g.ResetTransform();

  g.Dispose();

  GC.Collect();
  return dsImage;
  }
但是我想要的是这样的一个函数
旋转,我希望图片的内容大小不变
说简单点就是类似美图秀秀里饰品的旋转的那种。
麻烦哪位高手给个解决办法,或者改改这个函数呀?

------解决方案--------------------
帮你顶顶

------解决方案--------------------
这个函数有什么问题?
------解决方案--------------------
那是你的 生成后的图片 太小了.. 看看 Bitmap dsImage = new Bitmap(W, H); 这个的W,H是不是太小了.