我有以下代码,我尝试从字符串加载 SVG
const std::string svg =
"<svg height='200' width='200'><circle cx='100' cy='100' r='80' stroke='white' stroke-width='4' fill='black'/></svg>";
SDL_RWops *rw = SDL_RWFromConstMem(&svg, svg.size());
SDL_Surface *surface = IMG_Load_RW(rw, 1);
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);
Run Code Online (Sandbox Code Playgroud)
但是当我使用纹理时它不会绘制任何东西。
当我使用 IMG_LoadTexture 从文件加载相同的 SVG 时效果很好,所以我确信这是可以完成的,但我找不到方法。
我认为这里的问题可能是我如何将 SVG 传递到 SDL_RWFromConstMem
最后解决办法很简单,
const std::string svg =
"<svg height='200' width='200'><circle cx='100' cy='100' r='80' stroke='white' stroke-width='4' fill='black'/></svg>";
SDL_RWops *rw = SDL_RWFromConstMem(svg.c_str(), svg.size());
SDL_Surface *surface = IMG_Load_RW(rw, 1);
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2159 次 |
| 最近记录: |