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 C#. 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 C#. More on getting started with csXImage in C#.
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(DateTime.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 C# 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",
"Description or title").ToString();
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.
© 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.