September 28th, 2012, 04:26 PM
LOAD,SAVE and RETRIVE PICTURE FROM MySql database USING DELPHI - HELP PLEASE !!!
I need help with delphi project. I use delphi 2007 and MySql Database.
1. I want to load picture from TOpenPictureDialog to TImage (or TDBImage).
2. Picture from Timage (or TDBImage) I want to save to MySql database in table Picture field 'IMG'(longblob).
3. I want to retrieve image from my database table 'IMG' and show in TImage (or TDBImage).
4. I will have DBGrid on my main form. When I clik on GBgrid row or when I scroll GBGrid I want to see that picture are changing.
5. How to convert jpg to gif, or how to Shrink picture or limit picture to be H:161px and W:138px, that is a size of my TImage.
My database(MySql) have 4 table (contacts, city, country and picture).
Database will be small maybe 200 contacts so I think that saving picture in database is not a problem.
On my Main form I have DBGrid, TImage (or TDBImage), AddContact button, ChangeContact Button, DeleteContact Button,
ChoosePicture Button, Save and Cancel Button, and DBEdit's from AdoDataSet,
TAdoConnection,TAdoDataSet and DataSource, TOpenPictureDialog.
This is my database:
I have screenshot of my demo project .
Thank you for your time and knowledge.
September 28th, 2012, 06:20 PM
Presumably you would use:
I have not worked with MySQL, so I do not know the best syntax for transferring to and from MySQL BLOBs.
Perhaps using TBlobField or perhaps using some custom MySQL component?
HTH - Clive
September 29th, 2012, 12:02 AM
Maybe this may help.
September 29th, 2012, 03:40 AM
I use TImage.Picture.SaveToStream and TImage.Picture.LoadFromStream.
I can save picture in my database, but problem is when I want do retrieve
picture and show in TImage.
September 29th, 2012, 03:45 AM
I Read post on http://stackoverflow.com/a/4204076, I can save picture in my database, but I cant retrieve picture and show on Timage.
September 29th, 2012, 03:49 AM
Need Example - Please.
Can somebody post some small project example How to save a (Jpeg) image to MySql and retrieve it later using Delphi?
September 29th, 2012, 05:28 AM
I wrote a tutorial about this. Here is its url: http://forum.codecall.net/topic/67212-storing-images-in-database-mysql-and-ms-access-example/#entry617175
Note that in the tutorial I was using Zeos library to work with MySQL server.
October 3rd, 2012, 03:34 PM
I do this on a regular basis, but I never use Blobs etc. I simply put the local file address as a text field and retrieve this info into TImage as the the path to that pic. It is much faster this way.
eg: in a field of you database, "mypics" i have the text stored as: 'C:\mypics\fish.jpg'. I retrieve this as a variable, eg: "thepic:= row;
Now in Timage I simply retrieve this field data as: MyImage.Picture.LoadfromFile:= thepic;