如何将图像存储在 BLOB 中?
我找不到关于如何将图像存储到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果映像位于 MySQL 主机上,则可以使用
LOAD_FILE()
用于将图像存储在 BLOB 中的命令:确保 MySQL 可以读取该图像文件,并确保您的 MySQL 用户具有
文件权限。
要授予
FILE
权限,请以 root 身份登录并执行:If the image is located on your MySQL host, you could use the
LOAD_FILE()
command for storing an image in a BLOB: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:最简单的方法是将某些二进制图像文件的内容存储在 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.