如何将图像存储在 BLOB 中?

发布于 2024-08-14 12:25:56 字数 79 浏览 2 评论 0原文

我找不到关于如何将图像存储到 BLOB 的有用代码,请帮助我编写一些代码,我还可以在 GUI 中将这些图像从 MySQL 显示到我的桌面窗格吗?

I can not find useful code for how storing the images into BLOB ,please help me with some code and also can I show those images from MySQL to my desktop pane in GUI?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不念旧人 2024-08-21 12:25:56

如果映像位于 MySQL 主机上,则可以使用 LOAD_FILE() 用于将图像存储在 BLOB 中的命令:

-- Using the following table as an example:
CREATE TABLE MyTable (
   image  BLOB
);

-- This will insert a file in a BLOB column.
INSERT INTO MyTable (image) VALUES(LOAD_FILE('/tmp/image.png'));

确保 MySQL 可以读取该图像文件,并确保您的 MySQL 用户具有 文件权限。

要授予 FILE 权限,请以 root 身份登录并执行:

GRANT FILE ON *.* TO 'mysql_user'@'localhost';

If the image is located on your MySQL host, you could use the LOAD_FILE() command for storing an image in a BLOB:

-- Using the following table as an example:
CREATE TABLE MyTable (
   image  BLOB
);

-- This will insert a file in a BLOB column.
INSERT INTO MyTable (image) VALUES(LOAD_FILE('/tmp/image.png'));

Make sure that the image file is readable by MySQL, and also make sure that your MySQL user has the FILE privilege.

To grant the FILE privilege, log-in as root and execute:

GRANT FILE ON *.* TO 'mysql_user'@'localhost';
萧瑟寒风 2024-08-21 12:25:56

最简单的方法是将某些二进制图像文件的内容存储在 blob 中,提取它们,将它们写入文件并使用某种图像文件解析器打开该文件。或者,如果您真的很棘手,可以在将 blob 从数据库中拉出后直接使用相同的图像解析器从内存中读取数据。

我假设您有某种 ImagePane 小部件,如果您可以向它提供图像文件,它可以处理 GUI 显示。

Easiest way is to store the contents of some binary image file in the blob, extract them, write them to a file and open that file with an image file parser of some kind. Or, if you're really tricky, use that same image parser to read the data from memory directly after pulling the blob out of the DB.

I'm assuming you've got some sort of ImagePane widget that can handle the GUI display if you can provide an image file to it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文