将 html5 画布输出保存到我​​的 rails 应用程序 [英] save html5 canvas output to my rails app

查看:14
本文介绍了将 html5 画布输出保存到我​​的 rails 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 html5 画布的内容保存到我的 Rails 应用程序中.我找到了

I am trying to save the content of a html5 canvas to my Rails app. I found the

var url = canvas.toDataURL('image/png');

但我不知道如何将其放入我的帖子/表单中.

but I cant figure out how get that into my post/form.

我使用carrierwave 来处理图像,但我希望用户在画布上绘制一个图像,而不是上传图像.

Im using carrierwave to handle images but instead of uploading an image I want the user to draw one on the canvas.

我正在考虑将表单的输入文件设置为此内容,但这似乎不是它的工作方式

I was thinking of something like setting the input file of the form to this content but that does not seem to be the way it works

或者我不应该使用载波?

Or maybe I should not be using the carrier wave?

谢谢

推荐答案

只需将 url 的内容放在隐藏字段中即可.

simply place the content of url in an hidden field.

<input type="hidden" name="canvascontent" id="canvascontent" />

在 javascript 中(使用 jquery):

in javascript (with jquery):

var url = canvas.toDataURL('image/png');
$("#canvascontent").val(url);

这篇关于将 html5 画布输出保存到我​​的 rails 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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