Writing EXIF data using Visual Basic (VB6) and csXImage

Here are some code fragments showing how to use the ActiveX control csXImage to write Exif data to JPEG and TIFF images. The code is written in Visual Basic (VB 6). It is assumed that you have already installed either the full or trial version of csXImage and have added a control to a form in Visual Basic. More on getting started with csXImage in VB.

The Exif data is usually written at the time that the image is created, usually by the camera or scanner. Most of the EXIF attributes should not be edited because they are related to the camera settings or conditions at the time of creating the image, but some attributes, such as the description and copyright information, can be edited separately. The code fragments on this page form an extension to the csXImage instructions.

The ExifSetAttribute method

csXImage does not store a separate property for each EXIF attribute. Instead it uses a single method for setting all the attributes, which must be called with the attribute name as one parameter and the new value in string form as the other parameter. The following code fragment shows how to set four EXIF attributes. It assumes that the csXImage object has been created with the default name ImageBox1 and a JPG or TIFF image has been loaded.

ImageBox1.ExifSetAttribute "ImageDescription", "Description or title of the image."
ImageBox1.ExifSetAttribute "Artist", "The author of the image."
ImageBox1.ExifSetAttribute "Copyright", "A copyright notice"
ImageBox1.ExifSetAttribute "DateTime", ImageBox1.ExifDateToString(Now)

The first parameter of ExifSetAttribute is the name of the EXIF tag which must be a recognised tag name, although it is not case sensitive. The second parameter is the new value, and this must be a string even if the attribute that is stored is not a string. To set the DateTime attribute the current date/time is passed to the ExifDateToString method where it is converted from an ActiveX date/time to the correct format of string.

Checking the data has been written

The ExifSetAttribute method has a Boolean return value which is true when the value was set correctly but false if it was not set. The method does not return an error. If the tag name is not recognised or if the data is in an incorrect format, the return value will be false.

For example:

Label1.Caption ImageBox1.ExifSetAttribute("ImageDescription", "A new description")

Note that the ExifSetAttribute parameters are enclosed in brackets when the return value is used.

EXIF attributes which might be edited after creating the image

We do not provide a list of the available EXIF attributes, as there are over 100 different attributes. The following tags are the ones that are most likely to be edited. The first are all strings.

ImageDescription - Image title

Software - Software used

Artist - Person who created the image

Copyright - Copyright holder

The next are date/time values.

DateTime - File change date and time

DateTimeOriginal - Date and time of the original data generation

DateTimeDigitized - Date and time of digital data generation

More on reading EXIF attributes.

Summary of VB related pages.

Cookies

This site uses cookies for functionality, traffic analysis and for targeted advertising. Click the Accept button to accept our Cookie Policy. The Cookie Policy page offers configuration for a reduced set of cookies for this site.