示例#1
0
        public static Bitmap RotateImage(Image inputImg, double degreeAngle)
        {
            PointF[] pointF         = new PointF[] { new PointF(0f, 0f), new PointF((float)inputImg.Width, 0f), new PointF(0f, (float)inputImg.Height), new PointF((float)inputImg.Width, (float)inputImg.Height) };
            PointF[] rotationPoints = pointF;
            PointMath.RotatePoints(rotationPoints, new PointF((float)inputImg.Width / 2f, (float)inputImg.Height / 2f), degreeAngle);
            Rectangle bounds        = PointMath.GetBounds(rotationPoints);
            Bitmap    rotatedBitmap = new Bitmap(bounds.Width, bounds.Height);
            Graphics  g             = Graphics.FromImage(rotatedBitmap);

            try
            {
                g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                Matrix m = new Matrix();
                m.RotateAt((float)degreeAngle, new PointF((float)inputImg.Width / 2f, (float)inputImg.Height / 2f));
                m.Translate((float)(-bounds.Left), (float)(-bounds.Top), MatrixOrder.Append);
                g.Transform = m;
                g.DrawImage(inputImg, 0, 0);
            }
            finally
            {
                if (g != null)
                {
                    ((IDisposable)g).Dispose();
                }
            }
            return(rotatedBitmap);
        }
示例#2
0
 public static void RotatePoints(PointF[] pnts, PointF origin, double degreeAngle)
 {
     for (int i = 0; i < (int)pnts.Length; i++)
     {
         pnts[i] = PointMath.RotatePoint(pnts[i], origin, degreeAngle);
     }
 }
示例#3
0
        public static Rectangle GetBounds(PointF[] pnts)
        {
            RectangleF boundsF   = PointMath.GetBoundsF(pnts);
            Rectangle  rectangle = new Rectangle((int)Math.Round((double)boundsF.Left), (int)Math.Round((double)boundsF.Top), (int)Math.Round((double)boundsF.Width), (int)Math.Round((double)boundsF.Height));

            return(rectangle);
        }
示例#4
0
        public static PointF RotatePoint(PointF pnt, PointF origin, double degreeAngle)
        {
            double radAngle = PointMath.DegreeToRadian(degreeAngle);
            PointF newPoint = new PointF();
            double deltaX   = (double)(pnt.X - origin.X);
            double deltaY   = (double)(pnt.Y - origin.Y);

            newPoint.X = (float)((double)origin.X + (Math.Cos(radAngle) * deltaX - Math.Sin(radAngle) * deltaY));
            newPoint.Y = (float)((double)origin.Y + (Math.Sin(radAngle) * deltaX + Math.Cos(radAngle) * deltaY));
            return(newPoint);
        }
示例#5
0
        public static PointF RotatePoint(PointF pnt, double degreeAngle)
        {
            PointF pointF = PointMath.RotatePoint(pnt, new PointF(0f, 0f), degreeAngle);

            return(pointF);
        }