如何将位图旋转任意角度? [英] How do you rotate a bitmap an arbitrary number of degrees?

查看:96
本文介绍了如何将位图旋转任意角度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个位图:

Bitmap UnitImageBMP

我需要将其旋转任意角度.我该怎么做呢?RotateFlip方法将仅以90度为增量旋转.

And I need to rotate it an arbitrary number of degrees. How do I do this? The RotateFlip method will only rotate in increments of 90 degrees.

推荐答案

我做了一些搜索,发现了这一点:

I did some searching for you and found this:

public static Bitmap RotateImage(Bitmap b, float angle)
{
  //create a new empty bitmap to hold rotated image
  Bitmap returnBitmap = new Bitmap(b.Width, b.Height);
  //make a graphics object from the empty bitmap
  using(Graphics g = Graphics.FromImage(returnBitmap)) 
  {
      //move rotation point to center of image
      g.TranslateTransform((float)b.Width / 2, (float)b.Height / 2);
      //rotate
      g.RotateTransform(angle);
      //move image back
      g.TranslateTransform(-(float)b.Width / 2, -(float)b.Height / 2);
      //draw passed in image onto graphics object
      g.DrawImage(b, new Point(0, 0)); 
  }
  return returnBitmap;
}

这篇关于如何将位图旋转任意角度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆