我正在画一条从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度的线。
请引导我朝正确的方向走。
谢谢
发布于 2016-03-15 15:52:23
假设在float angle中有您想要的角度,只需在绘制这条线之前插入这三条线:
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()!
https://stackoverflow.com/questions/36015098
复制相似问题