如何从正在处理Javascript模式的草图中导出图像或PDF? [英] How to export an image or PDF from a Processing Javascript mode sketch?

查看:120
本文介绍了如何从正在处理Javascript模式的草图中导出图像或PDF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

处理2个"Java模式"(以前称为标准模式")具有一些简单的选项来输出图形,例如 saveFrame()

Processing 2 'Java mode', previously known as 'standard mode', has some easy options to output graphics like saveFrame() or the PDF Export Library.

现在,网络友好的"JavaScript模式"(基于 Processing.js 项目)可以托管一个可以轻松地进行草绘(通过HTML画布),但是使用文件时我找不到太多有关文件输出的信息.

Now, the web friendly 'Javascript mode' (based on the Processing.js project) allows one to host a sketch easily (by way of HTML canvas), but I can't find much about file output when using it.

如何使"Javascript模式"草图保存SVG或PDF?

How can I make my 'Javascript mode' sketch save SVG or PDF?

(不幸的是,我不懂Javascript,所以答案可能并不假定它是知识)

(Unfortunatly I don't know Javascript, so the answer might not assume knowledge of it)

推荐答案

默认情况下,Processing的javascript模式使用HTML5 Canvas进行渲染.您可以使用画布的HTML5 toDataURL方法来导出PNG.

The javascript mode of Processing utilizes HTML5 Canvas by default for rendering. You can use the HTML5 toDataURL method of canvas in order to export a PNG.

https://developer.mozilla.org/zh-CN /docs/Web/API/HTMLCanvasElement

实际上,这就是 save() Processing.js 中的参考,您会注意到用于导出PDF的功能处理中的(不可用)(用红色表示).

In fact, that is what save() and saveFrame() do in Processing.js. If you look throug the reference in Processing.js you'll notice that the functions you would use to export PDF in Processing are unavailable (indicated by red).

似乎无法从画布导出为PDF.但是,有一些框架可将画布导出到SVG.也已经在此提出.

Exporting to PDF from canvas does not seem possible. However, there are a few frameworks that export canvas to SVG. It has been asked here before as well.

此处是从SVG到画布再返回的广泛研究.底部是您可以使用的优秀工具包概述.但是,将它们与Processing.js混合在一起并非易事.

Here is an extensive study for going from SVG to canvas and back again. Towards the bottom there is an excellent roundup of toolkits you can use. However, mixing these in with Processing.js is non-trivial.

如果您不太了解Java脚本,并且需要以Java脚本而不是Java格式导出为PDF或SVG,那么我建议使用其他工具箱之一.这是很棒的页面展示了Processing.js,Paper.js和Raphael入门的基础.您会注意到这没什么不同,如果您知道正在处理,那您就可以了.

If you don't know Javascript well and you need to export to PDF or SVG in Javascript and not Java then I would suggest one of these other toolkits. Here is a great page that shows the basics of getting started on Processing.js vs Paper.js vs Raphael. You'll notice that is isn't too different, if you know Processing then you should be ok.

Processing.js也可以呈现为 WebGL ,但是没有SVG或本机或通过我知道的任何工具包进行的PDF导出选项.

Processing.js can also render to WebGL but that doesn't have either an SVG or PDF export option natively or through any toolkit that I know of.

这篇关于如何从正在处理Javascript模式的草图中导出图像或PDF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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