1. Tech

Your suggestion is on its way!

An email with a link to:

http://delphi.about.com/od/database/l/aa030601a.htm

was emailed to:

Thanks for sharing About.com with others!

Pictures inside a database
Page 1: Working with BLOBs. Storing pictures in Access.
 More of this Feature
• Page 2: DBImage.NOT
• 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
 Elsewhere on the Web
• BMP in Access/ADO
 

These days developing database applications requires more than just operating with textual or numeric data. If you are, for example, developing an Internet/intranet or multimedia based application, frequently there is a need to display pictures along with text from a database.

In this third chapter of the Delphi database course, we'll see how to pull out and display the graphical data (images) inside an Access database with ADO. Don't be worried with the fact that working with images inside an Access database requires more database programming skills than this course has provided so far. Let's pretend that we know more to get more.

If you have followed this course from the beginning (specially the second chapter), you know how to connect to a database and display the Applications (from our working aboutdelphi.mdb database) table in a DBGrid. Remember, we used 3 data components: DBGrid, ADOTable and DataSource to get and display the data from the Applications table.
Back in the first chapter when we created our database, the last filed in the Applications table was left blank (after filling our database with some dummy data). The last field has the name Picture and is of the OLE object type.

If you scroll right to the last column of the DBGrid you'll see something like:

Blob in DBGrid

When using MS Access, we can store images (and other large data objects such as sound or video) in a field that has the OLE object type. This type of data is referred to as a Binary Large Object Bitmap (BLOB).

Naturally when working with images, several types of picture formats are available. The most commonly used include JPEG, GIF and BMP. JPEG format has proven to be widely accepted by Web masters because of the small amount of storage required (in other words JPEGs are smaller than BMPs in bytes).

Delphi, of course, has means of handling BMP, GIF and JPEG graphic formats. The rest of this article will deal with JPEG file formats.

  Storing pictures in Access
Before going on to discussion about displaying the image inside a table within a Delphi form, we need to add some graphical data to our database.

Start Access and open the aboutdelphi.mdb database. Open the Applications table (it should have one row of data) and select the Picture field.

A table in Access

To add an image do the following:

1. Select Insert|Object... this will display the Insert Object dialog box.

MS Access...Insert Object

2. Click on the Browse button, this pops up the Browse open dialog. Note: you probably have some .jpg files on your computer, so you could use those, or if you have Win 98 and newer, MS Paint will save pictures in this format, as will many other programs. Navigate to a directory where your pictures are stored and select one.

Note: the text in the Picture field holds the name of an executable used to work with JPEG files on your computer. Of course you don't see the picture in a table grid. To actually see the graphics double click that field. This will load the image within the JPG type associated application.

Now, when we have a picture inside a database, let's see how to display it inside a Delphi form. We already have a Delphi form with data components on it from the second chapter of this course.

Next page > Pulling the Jpeg with DBImage - the wrong way > Page 1, 2, 3, 3, 5

©2014 About.com. All rights reserved.