Save jpeg to blob in mydac c++builder6

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Markcr

Save jpeg to blob in mydac c++builder6

Post by Markcr » Mon 25 Jul 2005 16:56

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.

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Tue 26 Jul 2005 09:00

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.

steve_reeves
Posts: 1
Joined: Tue 31 May 2005 22:46

Post by steve_reeves » Tue 26 Jul 2005 17:08

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.

markcr

Still no luck...

Post by markcr » Wed 27 Jul 2005 10:44

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?

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Wed 27 Jul 2005 14:04

MyDAC doesn't analyse contents of BLOB, VCL does it. Most likely, C++Builder cannot process JPG format you pass.

Thomas J.
Posts: 95
Joined: Mon 21 Nov 2005 12:16
Location: Germany

Re: Still no luck...

Post by Thomas J. » Fri 09 Dec 2005 10:47

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 ...

Guest

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

Post by Guest » Sat 27 May 2006 01:24

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.

ashlar

Post by ashlar » Wed 07 Jun 2006 17:19

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?

Thomas J.
Posts: 95
Joined: Mon 21 Nov 2005 12:16
Location: Germany

Post by Thomas J. » Thu 08 Jun 2006 08:44

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
....

ashlar

Post by ashlar » Thu 08 Jun 2006 14:42

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?

ashlar

Post by ashlar » Thu 08 Jun 2006 14:55

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?

ashlar

Post by ashlar » Thu 08 Jun 2006 16:56

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();

Guest

Loading an image into MySQL BLOB field

Post by Guest » Wed 26 Jul 2006 18:30

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.

Post Reply