简体   繁体   English

矢量绘图叠加 C#

[英]Vector drawing overlay C#

I want to draw vector lines and text on a overlay thats located in front of a picture.我想在位于图片前面的叠加层上绘制矢量线和文本。 At the moment i'm painting on a transparent descaled bitmap via drawings.graphic, but since im refreshing it on Mouse_move it's quite ressource heavy.目前我正在通过drawing.graphic在透明的除垢bitmap上作画,但由于我在Mouse_move上刷新它,所以它的资源很重。 Now i want to display my vectors directly via some svg viewer.现在我想通过一些 svg 查看器直接显示我的向量。 Does anybody know a good package to use?有人知道使用好的 package 吗? It just has to be performant, can be integrated in my xaml, use a transparent background and draw text and lines.它只需要高性能,可以集成到我的 xaml 中,使用透明背景并绘制文本和线条。 The NuGet packages i found, were either poorly documented or didn't work.我发现的 NuGet 软件包要么记录不充分,要么不起作用。 (VectSharp, SVG) (VectSharp,SVG)

As far as I know, nothing built in plays nicely with SVG.据我所知,SVG 没有任何内置功能。 Assuming you are not married to the idea of SVG there might be some other way to do it:假设您没有接受 SVG 的想法,可能还有其他方法可以做到:

  1. Use windows forms and do manual drawing in the paint-event.使用 windows forms 并在paint-event中进行手动绘图。 This may be slow if you have lots of graphics to draw.如果您要绘制大量图形,这可能会很慢。
  2. Draw to a bitmap and draw this to the screen (as you are currently seem to do).绘制到 bitmap 并将其绘制到屏幕上(正如您目前似乎所做的那样)。 Assuming you are not changing everything in each mouse move it might be possible to separate the bitmap in a foreground and background bitmap and only redraw the foreground on mouse move.假设您没有更改每次鼠标移动中的所有内容,则可以将 bitmap 分开在前景和背景 bitmap 中,并且仅在鼠标移动时重绘前景。
  3. Convert the svg graphics to xaml.将 svg 图形转换为 xaml。 Programs like inkscape can do this, but it might require some manual adjustments to get the correct enclosing elements etc.像inkscape这样的程序可以做到这一点,但它可能需要一些手动调整才能获得正确的封闭元素等。
  4. Convert the vector graphics objects to corresponding WPF graphics object and bind this to some suitable container object in the xaml code.将矢量图形对象转换为相应的 WPF 图形 object 并将其绑定到 Z44CC44B812511F4AFBA4581 代码中的某个合适的容器 object。
  5. Use something like SharpDX to get a lower level access to the graphics hardware.使用 SharpDX 之类的东西来获得对图形硬件的较低级别的访问。

You mentions performance issues, but performance for things like this is ensuring you do not redo work unnecessarily and ensuring the graphics primitives are sent to the hardware as efficiently as possible.您提到了性能问题,但此类事情的性能是确保您不会不必要地重做工作并确保尽可能有效地将图形基元发送到硬件。 It might for example be more efficient to draw a single GraphicsPath than drawing each line individually.例如,绘制单个GraphicsPath可能比单独绘制每条线更有效。

It would also be helpful if you could specify how many vectors you are attempting to draw.如果您可以指定尝试绘制的矢量数量,这也会很有帮助。 If we are talking about millions of lines it might be expected to be a bit slow unless you have a well optimized rendering pipeline.如果我们谈论的是数百万行,除非您有一个优化良好的渲染管道,否则它可能会有点慢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM