- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
下面的代码画了一个十字:
using (SolidBrush brush = new SolidBrush(Color.FromArgb(192, 99, 104, 113)))
{
using(GraphicsPath path = new GraphicsPath())
{
path.AddRectangle(new Rectangle(e.ClipRectangle.X + (e.ClipRectangle.Width - 40) / 2, e.ClipRectangle.Y, 40, e.ClipRectangle.Height));
path.AddRectangle(new Rectangle(e.ClipRectangle.X, e.ClipRectangle.Y + (e.ClipRectangle.Height - 40) / 2, e.ClipRectangle.Width, 40));
path.FillMode = FillMode.Winding;
e.Graphics.DrawPath(Pens.DimGray, path);
}
}
我想这样画:
我试过使用 Flatten();
和 CloseAllFigures();
但它们不起作用。
我正在寻找像 Union 这样的效果:
这可以用 GraphicsPath 实现吗?
最佳答案
使用Regions是可以的,但如果没有其他解决方案,则应使用GDI中的API FrameRgn来绘制区域的边框。
Graphics g = e.Graphics;
using (SolidBrush brush = new SolidBrush(Color.FromArgb(192, 99, 104, 113)))
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddRectangle(new Rectangle(e.ClipRectangle.X + (e.ClipRectangle.Width - 40) / 2, e.ClipRectangle.Y, 40, e.ClipRectangle.Height));
path.AddRectangle(new Rectangle(e.ClipRectangle.X, e.ClipRectangle.Y + (e.ClipRectangle.Height - 40) / 2, e.ClipRectangle.Width, 40));
path.FillMode = FillMode.Winding;
using (Region region = new Region(path))
{
IntPtr reg = region.GetHrgn(g);
IntPtr hdc = g.GetHdc();
IntPtr brushPtr = Win32.GetStockObject(Win32.WHITE_BRUSH);
IntPtr oldbrushPtr = Win32.SelectObject(hdc, brushPtr);
Win32.FrameRgn(hdc, reg, brushPtr, 1, 1);
Win32.DeleteObject(brushPtr);
Win32.SelectObject(hdc, oldbrushPtr);
region.ReleaseHrgn(reg);
g.ReleaseHdc();
}
}
}
关于c# - GraphicsPath 和 DrawPath - 删除相交线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28962998/
我有 drawpath 的这段代码,但没有显示任何内容,我不明白为什么。 //i move the path's starting point somewhere up here to a point
因此,我使用 CustomPainter 中的 drawPath 和 drawArc 创建了一个形状,PaintingStyle 是描边,但是当我将其更改为填充时,它只填充弧线而不是整个形状。我想用颜
我正在使用 gdiplus 来“描边”文本输出。在某些情况下,我们会在图形的顶部或底部看到一个“尖峰”,我不确定为什么。我们可以通过调整笔画宽度和字体大小来最小化这种情况,但这不是一个好的解决方案。我
下面的代码画了一个十字: using (SolidBrush brush = new SolidBrush(Color.FromArgb(192, 99, 104, 113))) { usin
我发现使用 Canvas.drawPath(path,paint) 比连续使用 Canvas.drawLine() 或使用 Canvas.drawLines() 慢得多。我无法提供确切的性能数据,但我
我在我的应用程序中同时使用 Rectangle 和 graphicspath 绘制线条,当使用 GraphicsPath 而不是使用 Rectangle 时,我面临着绘图中宽度和高度的丢失。 下面是重
关于我几周前问的这个问题 LinearGradientBrush does not render correctly 考虑以下代码: protected override void OnPaint(P
我正在为给定字符绘制字形轮廓,使用: QString myfname="FreeMono.ttf"; QRawFont *myfont=new QRawFont(myfname,324,QFont::
这是我编写的代码: private void touch_start(float x, float y) { mPath.reset(); mPath.moveTo(x, y);
在 Android 中,我使用 Canvas.drawPath( Path, Paint ) 来填充路径。我已将 Paint 变量设置为使用 BitmapShader 和要填充的样式。这种方法工作正常
我输入了一个在 Canvas 上绘制的程序。 它提供了一个弹出菜单,其中提供了 3 个绘图工具作为选项: 边划线边划线 根据屏幕上的起点和终点画线 画一个圆 此外,还有如下选项: 清除 撤消 在行上执
我想在计时器内画线。我应该使用哪一个?这两者有什么性能差异吗?我想要计时器中的情节线哪个更好? 最佳答案 在 Android 中,如果您正在绘制大量连接线(如 MapView 上的路线),请尝试使用“
我是一名优秀的程序员,十分优秀!