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 VB.NET. 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.NET.
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.
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 AxImageBox1 and a JPG or TIFF image has been loaded.
AxImageBox1.ExifSetAttribute("ImageDescription", "Description or title.")
AxImageBox1.ExifSetAttribute("Artist", "The author of the image.")
AxImageBox1.ExifSetAttribute("Copyright", "A copyright notice")
AxImageBox1.ExifSetAttribute("DateTime", AxImageBox1.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 a VB.NET date/time to the correct format of string.
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.Text = AxImageBox1.ExifSetAttribute("ImageDescription", "New description.")
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.NET related pages.
© Chestysoft, 2024.
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.