Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying image from DB

Status
Not open for further replies.

pointtozero

Programmer
Dec 15, 2010
2
Hiya,

I have a valid mysql connection to a MySQL database. What I want is to display a picture from the DB in TImage control. The pictures are stored as BLOB and LONGBLOB data types. This is how I get the image:

Code:
mysql_query(conn, "SELECT picture FROM customers WHERE name='John Smith'"); 
res = mysql_store_result(conn); 
row = mysql_fetch_row(res);

So, row[0] contains the image data, but it's char *. I have no idea how to display this array of char in the TImage control. Help me, please.

I'm using C++ Builder 6 and MySQL API for connecting.

Thank you!
 
Never mind, I've found a way how to do that.

Code:
TMemoryStream *str = new TMemoryStream;
str->WriteBuffer(row[0], mysql_fetch_lengths(res)[0]);
str->Position = 0;

TJPEGImage *img = new TJPEGImage;
img->LoadFromStream(str);

Image1->Picture->Assign(img);

img->Free();
str->Free();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top