svg - 如何通过从内存加载 svg 来创建 SDL 纹理?
问题描述
我有以下代码,我尝试从字符串加载 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);
但是当我使用纹理时,它不会绘制任何东西。
当我使用 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);
推荐阅读
- c# - 如何记录 Where 方法的结果?
- sql - 使用条件返回特定行
- excel - VBA Excel 2016根据另一列的值将一列中的表头粘贴到新表中
- php - PHP 用 xlsxwriter / ajax / 导出 xlsx 文件
- here-api - 显示无效凭据 - 反向地理编码 API
- node.js - 为 node.js 进程设置全局搜索目录
- shopify - Shopify 动态页面内容
- google-sheets - Google 表格 - 使用索引数组对值进行排序
- python - 在 python 程序中推断类型
- sql - 在“无效”列 SQL Server 2008 上计算 DATEDIFF