将Canvas元素转换为图像并存储在数据库中 [英] Converting Canvas element to Image and storing in database

查看:499
本文介绍了将Canvas元素转换为图像并存储在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将图像存储到我的服务器端数据库。一旦用户使用画布绘制并点击提交按钮,画布元素应转换为图片格式,然后我想将该图片存储到我的数据库中以备将来使用。我可以使用此图片验证用户下次访问我的网站。

I want to store the Image into my Server side Database. Once the user draw using canvas and hit a Submit button , Canvas Element should be converted to image format and then I want to store that Image into my database for further use. I can use this image to verify the user next time he visits my site.

任何人都可以帮我解决问题吗?我的服务器代码是以 Java Servlets

Can anyone help me to sort it out? My server code is written in Java Servlets

推荐答案

编写的 Canvas.toDataURL (),它将返回一个带有base64编码的PNG的字符串。然后,您可以将其存储为正常文本或解码并另存为文件。要把它放回画布你只需传递这个字符串作为 Canvas.draw(source,0,0)方法的源

Use Canvas.toDataURL() which will return a string with a base64 encoded PNG. You can then store it as a normal text or decode and save as a file. To put it back on canvas you simply pass this string as a source for Canvas.draw(source, 0, 0) method

小提琴: http://jsfiddle.net/9a7Xd/

这篇关于将Canvas元素转换为图像并存储在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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