ImageProcessor.Processors.Rotate.RotateImage C# (CSharp) Méthode

RotateImage() private méthode

Rotates an image to the given angle at the given position.
Based on
private RotateImage ( Image image, float rotateAtX, float rotateAtY, float angle ) : Bitmap
image Image The image to rotate
rotateAtX float The horizontal pixel coordinate at which to rotate the image.
rotateAtY float The vertical pixel coordinate at which to rotate the image.
angle float The angle in degrees at which to rotate the image.
Résultat System.Drawing.Bitmap
        private Bitmap RotateImage(Image image, float rotateAtX, float rotateAtY, float angle)
        {
            Rectangle newSize = ImageMaths.GetBoundingRotatedRectangle(image.Width, image.Height, angle);

            int x = (newSize.Width - image.Width) / 2;
            int y = (newSize.Height - image.Height) / 2;

            // Create a new empty bitmap to hold rotated image
            Bitmap newImage = new Bitmap(newSize.Width, newSize.Height, PixelFormat.Format32bppPArgb);
            newImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

            // Make a graphics object from the empty bitmap
            using (Graphics graphics = Graphics.FromImage(newImage))
            {
                // Reduce the jagged edge.
                GraphicsHelper.SetGraphicsOptions(graphics);

                // Put the rotation point in the "center" of the image
                graphics.TranslateTransform(rotateAtX + x, rotateAtY + y);

                // Rotate the image
                graphics.RotateTransform(angle);

                // Move the image back
                graphics.TranslateTransform(-rotateAtX - x, -rotateAtY - y);

                // Draw passed in image onto graphics object
                graphics.DrawImage(image, new PointF(x, y));
            }

            image.Dispose();
            return newImage;
        }