Draw line rotated at an angle over bitmap

前端 未结 1 1742
予麋鹿
予麋鹿 2021-01-24 20:23

I am drawing a line from centre of png image to top in below code:

    private string ProcessImage(string fileIn)
    {
        var sourceImage = System.Drawing.         


        
相关标签:
1条回答
  • 2021-01-24 21:05

    Let's assume you have the angle you want in a float angle all you need to do is to insert these three lines before drawing the line:

        g.TranslateTransform(x, y);   // move the origin to the rotation point 
        g.RotateTransform(angle);     // rotate
        g.TranslateTransform(-x, -y); // move back
    
        g.DrawLine(new Pen(Color.Black, (float)5), new Point(x, 0), new Point(x, y));
    

    If you want to draw more stuff without the rotation call g.ResetTranform() !

    0 讨论(0)
提交回复
热议问题