Raphael中的SVG文件,可以使用吗? [英] SVG files in Raphael, can they be used?

查看:144
本文介绍了Raphael中的SVG文件,可以使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要通过Raphael显示的SVG文件(每个svg文件都是我要绘制的树中的一个节点,树的实际连接将由raphael进行).我尝试过类似的事情:

I have an SVG file that I would like to display via Raphael (each svg file is a node in a tree I'm trying to draw, the actual connections of the tree will be made by raphael). I tried something like:

var vector_image = paper.image("test.svg", 50,50,50,50);

但没有骰子,似乎只有png或jpeg之类的真实"图像文件被接受了吗?我发现这很奇怪,因为Raphael本身使用可缩放矢量图形.

but no dice, seems only "real" image files like png or jpeg are accepted? I find this very strange as Raphael itself uses Scalable Vector Graphics.

反正是否存在(缺少将SVG文件解析为javascript代码片段并将其粘贴到html文档中)以使用Raphael(或任何其他基于矢量的javascript图形引擎)显示现有SVG文件的方法?

Is there anyway (short of parsing the SVG files into javascript snippets and pasting them into the html document) to display existing SVG files using Raphael (or any other vector based javascript graphical engine?)

如果必须进行解析,那么除了手动抓取文件之外,还有什么简单的方法可以做到这一点?我正在Ruby on Rails服务器上运行此代码,因此,如果可能的话,我希望避免使用该框架之外的解决方案(我听说通过此站点提供了一个PHP解决方案...我宁愿手动编写代码,也不想手工编写代码)在该项目中添加另一种语言.)

If parsing it will have to be, is there any easy way to do this, short of just manually scraping the files? I'm running this code on a Ruby on Rails server, so I'd like to avoid solutions outside this framework, if possible (I've heard of one PHP solution through this site...I'd rather code by hand than add another language onto this project).

-珍妮

推荐答案

当前无法使用Raphael显示现有的SVG,并且显然没有实现SVG编辑的计划(请参见 Snap.svg ,它可以通过其 Snap.load() 函数.

It's currently not possible to display existing SVG with Raphael, and there are apparently no plans for the implementation of SVG editing (see this forum post). As for alternative JavaScript libraries, a newer alternative is Snap.svg, which can load external SVG files via its Snap.load() function.

这篇关于Raphael中的SVG文件,可以使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆