gpt4 book ai didi

mysql - 将 Canvas 绘制的图像保存到mysql数据库

转载 作者:搜寻专家 更新时间:2023-10-30 20:20:58 27 4
gpt4 key购买 nike

我想知道解决这个问题的最佳方法。我正在尝试将用户在 HTML5 Canvas 上绘制的图像保存到我的数据库中,以便稍后检索它。

我使用以下代码为图像创建了 base64 数据字符串,连接到一个简单的按钮点击处理程序:

var image_data = $("#drawing_canvas").get(0).toDataURL('image/png');

我正计划将该数据保存到我的数据库中,然后稍后使用类似这样的方法检索它:

var myImage = new Image();
myImage.src = imgData;
ctx.drawImage(myImage, 0, 0);

但是,这些 base64“字符串”似乎包含大量数据。我想知道是否有更好的方法将这些图像保存到我的数据库中?我还没有找到将实际图像保存为 .png 的方法。我可以让它在新的浏览器选项卡中以 png 格式打开,但这就是我目前遇到的问题。

或者将这些 base64 数据字符串存储在我的数据库中(我想是“文本”列)是否合适?

提前致谢。

最佳答案

您想使用 BLOB 类型。以下是 MySQL 文档对它的描述:

BLOB values are treated as binary strings (byte strings). They have no character set, and sorting and comparison are based on the numeric values of the bytes in column values. TEXT values are treated as nonbinary strings (character strings). They have a character set, and values are sorted and compared based on the collation of the character set.

http://dev.mysql.com/doc/refman/5.0/en/blob.html

关于mysql - 将 Canvas 绘制的图像保存到mysql数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6157949/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com