使用C#在一行上绘制阴影 [英] Draw shadow on a line using C#
本文介绍了使用C#在一行上绘制阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在线的不同角度添加阴影
TopLeft,
TopCenter,
TopRight,
MiddleLeft,
MiddleCenter,
MiddleRight,
BottomLeft,
BottomCenter,
BottomRight
我该怎么做?
我试过的:
I want to add shadow on line in different angle of the line
TopLeft,
TopCenter,
TopRight,
MiddleLeft,
MiddleCenter,
MiddleRight,
BottomLeft,
BottomCenter,
BottomRight
How can i do that ?
What I have tried:
GraphicsPath path = new GraphicsPath();
path.AddLine(10, 200, 200, 200);
using (Graphics G = this.CreateGraphics())
{
var myPen = new Pen(Color.SkyBlue, 50);
G.DrawLine(myPen, new Point(10, 200), new Point(200, 200));
drawShadow(G, Color.Green, path, 25);
}
void drawShadow(Graphics G, Color c, GraphicsPath GP, int d)
{
Color[] colors = getColorVector(c, this.BackColor, d).ToArray();
for (int i = 0; i < d; i++)
{
G.TranslateTransform(0, 1); // <== shadow vector!
using (Pen pen = new Pen(colors[i], 1.75f)) // <== pen width (*)
G.DrawPath(pen, GP);
}
G.ResetTransform();
}
List<Color> getColorVector(Color fc, Color bc, int depth)
{
List<Color> cv = new List<Color>();
float dRed = 1f * (bc.R - fc.R) / depth;
float dGreen = 1f * (bc.G - fc.G) / depth;
float dBlue = 1f * (bc.B - fc.B) / depth;
for (int d = 1; d <= depth; d++)
cv.Add(Color.FromArgb(255, (int)(fc.R + dRed * d),
(int)(fc.G + dGreen * d), (int)(fc.B + dBlue * d)));
return cv;
}
推荐答案
使用模糊线条在c中绘制阴影 [ ^ ]
如何在椭圆上绘制阴影 [ ^ ]
参考这些链接。
Use fuzzy lines to draw shadows in c[^]
How to draw a drop shadow on ellipse[^]
Refer these links.
这篇关于使用C#在一行上绘制阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文