X
X
xawifoo2019-03-11 22:39:03
C++ / C#
xawifoo, 2019-03-11 22:39:03

How to rotate picturebox?

Hello!
There is a picturebox, under a certain condition, it is necessary to rotate by a certain degree.
5c86b93354ead486902310.png
Can you please tell me how to implement this function?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Satangelus, 2019-03-12
@xawifoo

public static Bitmap RotateImage(Image image, PointF offset, float angle)
{
    if (image == null)
        throw new ArgumentNullException("image");
        
    //create a new empty bitmap to hold rotated image
    Bitmap rotatedBmp = new Bitmap(image.Width, image.Height);
    rotatedBmp.SetResolution(image.HorizontalResolution, image.VerticalResolution);
    
    //make a graphics object from the empty bitmap
    Graphics g = Graphics.FromImage(rotatedBmp);
    
    //Put the rotation point in the center of the image
    g.TranslateTransform(offset.X, offset.Y);
    
    //rotate the image
    g.RotateTransform(angle);
    
    //move the image back
    g.TranslateTransform(-offset.X, -offset.Y);
    
    //draw passed in image onto graphics object
    g.DrawImage(image, new PointF(0, 0));
    
    return rotatedBmp;
}

C
CHolfield, 2019-03-12
@CHolfield

https://docs.microsoft.com/ru-ru/dotnet/api/system...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question