I can not find useful code for how storing the i开发者_运维技巧mages into BLOB ,please help me with some code and also can I show those images from MySQL to my desktop pane in GUI?
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';
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.
精彩评论