Page 1 of 1

Save jpeg to blob in mydac c++builder6

Posted: Mon 25 Jul 2005 16:56
by Markcr
I wish to have a user select a jpg picture, which is then displayed in am TImage component. The image is resized.

I then wish to save this resized image to the mysql database to a field named profilepicture using a mydac table component, NOT query component

I would the like to do the reverse, i.e. get it back from the database into a TImage component. I understand you can use streams but I have not been able to do so yet.

Posted: Tue 26 Jul 2005 09:00
by Ikar
The easiest for you is to use TDBImage instead of Timage. You can see an example of using TDBImage in Delphi applications at MyDAC packages.

Posted: Tue 26 Jul 2005 17:08
by steve_reeves
I was about to start a new thread with a question about TDBImage and MyDAC, I'm posting it here because I think it may be related.

I'm looking at the demo program for working with TDBImage and the MyDAC query component and it doesn't work with jpeg files. I get an error that it's an invalid bitmap image.

When I do the exact same thing with an Oracle table using the ODAC components it works fine. Also, it works fine with .BMP files.

Still no luck...

Posted: Wed 27 Jul 2005 10:44
by markcr
Well, I am able to save the images to the database easily, but I cannot use the example of MemoryStream to display the picture, it just displays nothing. i can though save the blob to a file and load the file in the image component, but this isn't ideal.

Anyone ever used c++ builder v6 to show an image from a mysql blob field?

Posted: Wed 27 Jul 2005 14:04
by Ikar
MyDAC doesn't analyse contents of BLOB, VCL does it. Most likely, C++Builder cannot process JPG format you pass.

Re: Still no luck...

Posted: Fri 09 Dec 2005 10:47
by Thomas J.
markcr wrote:Well, I am able to save the images to the database easily, but I cannot use the example of MemoryStream to display the picture, it just displays nothing. i can though save the blob to a file and load the file in the image component, but this isn't ideal.

Anyone ever used c++ builder v6 to show an image from a mysql blob field?
Yes I do, if you need still info then ...

Re: Save jpeg to blob in mydac c++builder6

Posted: Sat 27 May 2006 01:24
by Guest
Markcr wrote:I wish to have a user select a jpg picture, which is then displayed in am TImage component. The image is resized.

I then wish to save this resized image to the mysql database to a field named profilepicture using a mydac table component, NOT query component

I would the like to do the reverse, i.e. get it back from the database into a TImage component. I understand you can use streams but I have not been able to do so yet.

Posted: Wed 07 Jun 2006 17:19
by ashlar
This is a somehwat related question.

I have a DBImage component and when I load a image file into it...it displays just fine. But for some reason it doesn't put this loaded pic into the database. Any idea why this not is happening? And what would be the best way to do this?

Posted: Thu 08 Jun 2006 08:44
by Thomas J.
Please specify how you want to store the image in the database.
Are you using a data aware control or do you want to store the image by code? In case of code, show the code.
Do you get an error? Which error
....

Posted: Thu 08 Jun 2006 14:42
by ashlar
I get no errors. In fact if I copy and paste the bitmap into the DBImage component and move to a new record and then return to that record it is that record.
When I do load a bitmap file in with the below code...it doesn't save it to the database...even if you move to another record and come back. I am using a longblob field to save this image.

void __fastcall TForm1::JvXPButton_Load_Network_PicClick(TObject *Sender)
{
if(OpenPictureDialog1->Execute())
DBImage_Network_Pic->Picture->LoadFromFile(OpenPictureDialog1->FileName);
}


I am curious....if I wasn't using a data aware control how would you save a pic directly to a record blob field?

Posted: Thu 08 Jun 2006 14:55
by ashlar
Hmm actually I figured it out.

I guess I needed to do this:


MyTable_Site_ID_Examine->Edit();

DBImage_Network_Pic->Picture->LoadFromFile(OpenPictureDialog1->FileName);

MyTable_Site_ID_Examine->Post();


Isn't that a bit odd? Isn't it supposed to be a data-aware component?

Posted: Thu 08 Jun 2006 16:56
by ashlar
There is a free component out there that will show many different types of graphic formats...its called a JVDBImage component. It works well with databases and various graphic files.

The suite of free components is call Jedi vcl.

http://www.delphi-jedi.org/

Just beware...the help files are pretty poor.

I used this code to put a jpg (or any other type of image file in a database)

MyTable_Site_ID_Examine->Edit();
JvDBImage_Network_Pic->Picture->LoadFromFile(OpenPictureDialog1->FileName);
MyTable_Site_ID_Examine->Post();

Loading an image into MySQL BLOB field

Posted: Wed 26 Jul 2006 18:30
by Guest
An even easier way to do this is to interact directly with the data field. If you have a table named myTable with image field ImageField, you can do the following:

Code: Select all

MyTable->Edit();
MyTableImageField->LoadFromFile("C:\directory\myimage.bmp");
MyTable->Post();
The above code assumes you've declared a persistent field object for the ImageField field.

You can also use the TBlobField's LoadFromStream() method to get the image data directly from a stream.

You can use this method for any type of image file - the problem comes when you try to display the image in a TDBImage control - it only wants to display bitmaps! If you want to display other image types you're better off using a TImage and converting your BLOB's data to bitmaps on the fly.