| Pictures inside a database | |
|
The DBImage - take one All clear, put a DBImage on form and leave the DBImage1 name. To actually link a DBImage with a BLOB field in a Table we simply need to do the following assignment (using the Object Inspector):
DBImage1.DataSource = DataSource1 This should do the trick of displaying the JPEG image stored in the Picture field of the Applications table.
To see whether this assignment will work the only thing we have to do is to set the Active property of the ADOTable1 component to True. We can do this at design time with the Object Inspector. Once you set it you'll get the following:
The first thing I do when trying to do something new with Delphi is to "ask" Delphi Help for help. This is what the Help system replies: TDBImage (Data Controls page on the component palette) represents a graphic image from a BLOB (binary large object) field of the current record of a dataset. Use TDBImage to represent the value of graphic fields. TDBImage allows a form to display graphical data from a dataset. The DBImage is nothing more than a TImage component with some data aware properties. The two most important ones are: DataSource and Field. The DataSource property links the image component to a dataset. We have a DataSoure component named DataSource1 on our form that represent a dataset. The Field property indicates the field (in a table) that holds the image.
DBImage1.Field = Picture

Now what? Why does it say "Bitmap image is not valid." We have a JPEG picture not the BMP - is this the problem? Let's go back to the Help.
After a few clicks through the Help the conclusion is: to get the JPG inside a database we need to use the TJpegImage object. To display the picture we need the simple, non-data aware, version of the Image component. Even more we'll need to use streams to load a picture from a BLOB object. The Help states that we should use TADOBlobStream to access or modify the value of a BLOB or memo field in an ADO dataset.
Next page > Streaming the Jpeg - the wrong way > Page 1, 2, 3, 4, 5

