1. Home
  2. Computing & Technology
  3. Delphi Programming
Pictures inside a database
Page 2: Pulling the Jpeg with DBImage - the wrong way.
 More of this Feature
• Page 1: BLOBs in Access
• Page 3: Streaming JPG
• Page 4: JPG SOI marker
• Page 5: Project's Code
 Join the Discussion
"Post your views and comments to this chapter of the free Delphi database Programming Course"
Discuss!
  Related Resources
• free DB Course.TOC
• Delphi DB articles
 

  The DBImage - take one
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.

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
DBImage1.Field = Picture

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:

Bitmap image not supported

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

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming

©2009 About.com, a part of The New York Times Company.

All rights reserved.