Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在位图上以一定角度旋转绘制线_C#_.net_Bitmap_Gdi - Fatal编程技术网

C# 在位图上以一定角度旋转绘制线

C# 在位图上以一定角度旋转绘制线,c#,.net,bitmap,gdi,C#,.net,Bitmap,Gdi,我在下面的代码中画了一条从png图像中心到顶部的线: private string ProcessImage(string fileIn) { var sourceImage = System.Drawing.Image.FromFile(fileIn); var fileName = Path.GetFileName(fileIn); var finalPath = Server.MapPath(@"~/Output/" + fi

我在下面的代码中画了一条从png图像中心到顶部的线:

    private string ProcessImage(string fileIn)
    {
        var sourceImage = System.Drawing.Image.FromFile(fileIn);
        var fileName = Path.GetFileName(fileIn);
        var finalPath = Server.MapPath(@"~/Output/" + fileName);

        int x = sourceImage.Width / 2;
        int y = sourceImage.Height / 2;
        using (var g = Graphics.FromImage(sourceImage))
        { 
            g.DrawLine(new Pen(Color.Black, (float)5), new Point(x, 0), new Point(x, y));
        }
        sourceImage.Save(finalPath);

        return @"~/Output/" + fileName;
    }
这很好,我有一条线,它和图像中心成90度角。 现在我需要的不是90度的垂直线,而是接受用户输入的角度。如果用户输入45度,则线应在距离png图像中心45度处绘制

请给我指引正确的方向


谢谢

假设您在
浮动角度中具有所需的角度
只需在绘制线之前插入这三条线即可:

    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));
如果您想在不旋转的情况下绘制更多的内容,请调用
g.ResetTranform()