And*_*eas 1 c# asp.net graphics gradient rounded-corners
我到处寻找并搜索所有内容,但找不到任何好的东西.我需要的是一个能够绘制带圆角的图像(图形)的类(每个角上不同是一个加号),带有边框和渐变填充.
我发现的所有例子都有一些缺陷(如质量差,缺少功能等).
我将使用ashx绘制图像,然后将其显示给用户.
谢谢!
所述的GraphicsPath可以绘制相对自由形式的形状,然后可以用渐变画笔填充.下面的示例代码将创建一个带有两个不同圆角和渐变填充的矩形.
GraphicsPath gp = new GraphicsPath();
gp.AddLine(new Point(10, 10), new Point(75, 10));
gp.AddArc(50, 10, 50, 50, 270, 90);
gp.AddLine(new Point(100, 35), new Point(100, 100));
gp.AddArc(80, 90, 20, 20, 0, 90);
gp.AddLine(new Point(90, 110), new Point(10, 110));
gp.AddLine(new Point(10, 110), new Point(10, 10));
Bitmap bm = new Bitmap(110, 120);
LinearGradientBrush brush = new LinearGradientBrush(new Point(0, 0), new Point(100, 110), Color.Red, Color.Yellow);
using (Graphics g = Graphics.FromImage(bm))
{
g.FillPath(brush, gp);
g.DrawPath(new Pen(Color.Black, 1), gp);
g.Save();
}
bm.Save(@"c:\bitmap.bmp");
Run Code Online (Sandbox Code Playgroud)
这导致以下图像:
