Save jpeg to blob in mydac c++builder6
- 
				Markcr
 
Save jpeg to blob in mydac c++builder6
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.
			
									
									
						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.
- 
				steve_reeves
 - Posts: 1
 - Joined: Tue 31 May 2005 22:46
 
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.
			
									
									
						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...
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?
			
									
									
						Anyone ever used c++ builder v6 to show an image from a mysql blob field?
Re: Still no luck...
Yes I do, if you need still info then ...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?
- 
				Guest
 
Re: Save jpeg to blob in mydac c++builder6
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
 
- 
				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?
			
									
									
						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
 
- 
				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();
			
									
									
						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
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:
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.
			
									
									
						Code: Select all
MyTable->Edit();
MyTableImageField->LoadFromFile("C:\directory\myimage.bmp");
MyTable->Post();
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.