在 C++ 中渲染矢量图形 (.svg)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4176637/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 14:44:26  来源:igfitidea点击:

Render a vector graphic (.svg) in C++

c++windowsvector-graphicsallegro

提问by Brad

My and a friend are working on a 2D game where the graphics will be .svg files and we will scale them appropriately either by rasterizing them first, or rendering them directly on a surface (which still would require rasterization at some point).

我和一个朋友正在开发一个 2D 游戏,其中图形将是 .svg 文件,我们将通过首先光栅化它们或直接在表面上渲染它们来适当地缩放它们(这在某些时候仍然需要光栅化)。

The problem is, I've been looking all day to find a library that will allow me to take an .svg file and eventually get it to render in allegro. As far as I know, it would involve rasterization into some sort of format that allegro can read and then allegro could render the "flattened" image.

问题是,我一整天都在寻找一个可以让我获取 .svg 文件并最终让它在快板中呈现的库。据我所知,这将涉及将光栅化为某种快板可以读取的格式,然后快板可以渲染“扁平化”图像。

So what are some C++ libraries I could use for taking an .SVG file and "flattening" it so I can render it? The library obviously needs to support scaling too so I can scale the vector graphic then rasterize it.

那么我可以使用哪些 C++ 库来获取 .SVG 文件并将其“展平”以便渲染它?该库显然也需要支持缩放,以便我可以缩放矢量图形然后对其进行光栅化。

I'm using Windows and Visual C++ Express 2010.

我使用的是 Windows 和 Visual C++ Express 2010。

Any suggestions would be helpful as I am very lost right now:

任何建议都会有所帮助,因为我现在非常迷茫:

I've tried Cairo, but it only allows writing of .svg files and doesn't allow you to read the .svg file. I've also looked into librsvg which works with Cario, but I was having a lot of trouble getting it to work properly on Windows (because it has loads of GNOME dependencies). If you have any guides for getting these to work (on Windows) that would be great too.

我试过开罗,但它只允许写入 .svg 文件,不允许您读取 .svg 文件。我还研究了与 Cario 一起使用的 librsvg,但是我在让它在 Windows 上正常工作时遇到了很多麻烦(因为它有大量的 GNOME 依赖项)。如果您有让这些工作(在 Windows 上)工作的任何指南,那也会很棒。

采纳答案by Vijay Mathew

The wxsvg libraryallows loading and manipulating SVG files. Qt also has an SVG module.

wxsvg图书馆允许装载和操纵SVG文件。Qt 还有一个SVG 模块

回答by Jaime Ivan Cervantes

I'm coming a little late to the conversation, but I would suggest you to look at Nano SVG, an extremely lightweight svg renderer that doesn't need cairo/libsvg. I got nanosvg compiled and working in a couple of hours. It's very basic, but it gets the job done.

我的谈话有点晚了,但我建议你看看Nano SVG,一个不需要 cairo/libsvg 的非常轻量级的 svg 渲染器。我编译了 nanosvg 并在几个小时内工作。这是非常基本的,但它完成了工作。

回答by OlegMax

SVG++ libraryprovides advanced support for SVG reading, so that rendering SVG with allegro can be implemented in reasonable time.

SVG++ 库提供了对 SVG 读取的高级支持,因此可以在合理的时间内实现使用 allegro 渲染 SVG。

回答by igagis

I have recently put together an SVG renderer library in C++: https://github.com/igagis/svgren

我最近在 C++ 中组合了一个 SVG 渲染器库:https: //github.com/igagis/svgren

It uses Cairo for rendering to off-screen surface. Supports gradients and all kind of shapes.

它使用 Cairo 渲染到离屏表面。支持渐变和各种形状。

回答by Andrey A. Ugolnik

Personally, I using NanoSVG in my Simple Viewer GL. It's allowing me easy to load and rasterize SVG images in few lines of code. But this library has weak SVG support.

就个人而言,我在 Simple Viewer GL 中使用 NanoSVG。它让我可以用几行代码轻松加载和光栅化 SVG 图像。但是这个库对 SVG 的支持很弱。

回答by Samuel

https://github.com/sammycage/lunasvgis a nice svg parsing, rendering and manipulating library. It is written with pure c++

https://github.com/sammycage/lunasvg是一个不错的 svg 解析、渲染和操作库。它是用纯 C++ 编写的