Click here to Skip to main content
15,890,438 members
Articles / Programming Languages / Visual Basic
Article

The ExifWorks class

Rate me:
Please Sign up or sign in to vote.
4.43/5 (27 votes)
1 Feb 2006MIT2 min read 332.1K   8.9K   87   83
The ExifWorks is a class written in 100% pure managed VB.NET, which allows comfortable reading of embedded EXIF metadata.

What is EXIF

EXIF stands for Exchangeable Image File Format. This format is used for storing various metadata in images, and is widely used mainly in digital still cameras. More information about EXIF can be found here, or in the document Description of the EXIF file format by TsuruZoh Tachibanaya.

When I was trying to find any sources regarding comfort access from .NET environment to these data, I was not successful. So I wrote this class and gave it freely available as open source.

What is ExifWorks

ExifWorks is a class written in 100% pure managed VB.NET, which allows comfort reading and writing of embedded EXIF metadata. It has the following features:

  • Provides the TagNames Enum, which contains user-friendly constant names for all known EXIF parameter IDs.
  • Provides generic functions for reading EXIF parameters: GetInt16, GetInt32, GetString, and GetRational, as well as GetPropertyInt16, GetPropertyInt32, GetPropertyString, and GetPropertyRational. They may be used to simplify the access to all EXIF data from your custom application.
  • Provides a user-friendly abstraction layer for most of the common parameters, allowing easy work with EXIF data and their presentation to end users. The abstraction layer has been developed for presentation, so even if a value is not present, some data (in valid syntax) are provided. Either default values or values computed from other sources (i.e. shutter speed vs. exposure time) are provided. If you need exact data, use the generic functions instead.

The provided test application exread.exe shows working with the ExifWorks class.

Licensing

ExifReader/ExifWorks .NET library

Copyright (c) Michal A. Valášek - Altair Communícations, 2003-2006

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

The text of the GNU Lesser General Public License (LGPL) is available online here.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer Altairis
Czech Republic Czech Republic

Software architect and developer in Altairis, dev shop in Czech republic. Microsoft Most Valuable Professional (MVP) since 2004.


See my open source project at Codeplex.


Comments and Discussions

 
GeneralRe: Saving edits Pin
Zisha1-Aug-12 11:20
Zisha1-Aug-12 11:20 
GeneralRe: Saving edits Pin
chuasw2327-Feb-12 15:30
chuasw2327-Feb-12 15:30 
GeneralRe: Saving edits Pin
Member 148628508-Nov-22 9:53
Member 148628508-Nov-22 9:53 
QuestionHow to set / write "rational-data" like latitude / longitude ? [modified] Pin
scooterdd14-Aug-09 0:35
scooterdd14-Aug-09 0:35 
AnswerRe: How to set / write "rational-data" like latitude / longitude ? Pin
Drew Stegon19-Aug-09 17:28
Drew Stegon19-Aug-09 17:28 
QuestionAny way to write tags Pin
gerardkelly21-Jul-09 7:03
gerardkelly21-Jul-09 7:03 
GeneralCannot save ISO info Pin
waex9925-Jun-09 21:59
waex9925-Jun-09 21:59 
GeneralEXIF Thumbnail Pin
Scott Rippey21-Jun-09 9:50
Scott Rippey21-Jun-09 9:50 
Below is the code for extracting the Thumbnail image from the Exif data.
Public ReadOnly Property HasThumbnail() As Boolean
  Get
    Return IsPropertyDefined(TagNames.ThumbnailData)
  End Get
End Property
Private mThumb As Image
Public ReadOnly Property Thumbnail() As Image
  Get
    If mThumb Is Nothing Then
      ' Let's try to load the thumbnail from the raw bytes!
      Dim thumbData() As Byte = Me.GetProperty(TagNames.ThumbnailData)
      If thumbData IsNot Nothing Then
        Dim thumbStream As New IO.MemoryStream(thumbData)
        Try
          mThumb = Drawing.Image.FromStream(thumbStream)
        Catch ex As Exception
          'Couldn't load the thumbnail :( Reason? Unknown.
        End Try
      End If
    End If
    Return mThumb
  End Get
End Property


Also, when the image is loaded from a file, it normally has to load the entire full image, which takes a long time. If we tell the image not to load, it performs way better. This is especially useful if we're just trying to extract a thumbnail. So, below, I modified the constructor to skip loading the whole image.
Private shouldDisposeImage As Boolean
''' <summary>
''' Reads EXIF data from a file.
''' </summary>
''' <param name="FileName">Name of file to be loaded</param>
''' <param name="loadEntireImage">IF False, then ONLY the EXIF data is loaded, and not the entire image!  This saves a TON of time.  If True, then the entire image is loaded.</param>
''' <remarks></remarks>
''' <history>
''' [altair] 13.06.2004 Created
''' </history>
Public Sub New(ByVal FileName As String, Optional ByVal loadEntireImage As Boolean = False)
  'Me._Image = System.Drawing.Bitmap.FromFile(FileName)
  Dim fileStream As New System.IO.FileStream(FileName, IO.FileMode.Open, IO.FileAccess.Read)
  Me._Image = System.Drawing.Image.FromStream(fileStream, True, loadEntireImage)
  Me.shouldDisposeImage = True 'since we created the bitmap, we are responsible for destroying it
End Sub

''' <summary>
''' Disposes unmanaged resources of this class
''' </summary>
''' <remarks></remarks>
''' <history>
''' [altair] 10.09.2003 Created
''' </history>
Public Sub Dispose() Implements System.IDisposable.Dispose
  If shouldDisposeImage Then Me._Image.Dispose()
End Sub


modified on Tuesday, June 23, 2009 1:05 PM

GeneralRe: EXIF Thumbnail Pin
Drew Stegon17-Aug-09 5:57
Drew Stegon17-Aug-09 5:57 
AnswerRe: EXIF Thumbnail Pin
Scott Rippey17-Aug-09 8:29
Scott Rippey17-Aug-09 8:29 
GeneralRe: EXIF Thumbnail Pin
Drew Stegon18-Aug-09 13:18
Drew Stegon18-Aug-09 13:18 
GeneralRe: EXIF Thumbnail Pin
Scott Rippey18-Aug-09 20:05
Scott Rippey18-Aug-09 20:05 
GeneralRe: EXIF Thumbnail Pin
Drew Stegon19-Aug-09 11:04
Drew Stegon19-Aug-09 11:04 
GeneralRe: EXIF Thumbnail Pin
Drew Stegon18-Aug-09 13:37
Drew Stegon18-Aug-09 13:37 
Generalc# version with GPS feature (latitude, longitude) Pin
Member 425991919-Jun-09 22:41
Member 425991919-Jun-09 22:41 
GeneralOverwrite the existing file when saving. Pin
Drittsekken11-Jun-09 10:28
Drittsekken11-Jun-09 10:28 
GeneralLatitude/Longitude Pin
Melanie Hugglestone20-Mar-09 11:51
Melanie Hugglestone20-Mar-09 11:51 
GeneralRe: Latitude/Longitude Pin
Coffer7-Jun-09 6:49
Coffer7-Jun-09 6:49 
AnswerRe: Latitude/Longitude Pin
Member 425991919-Jun-09 22:43
Member 425991919-Jun-09 22:43 
GeneralRe: Latitude/Longitude Pin
Coffer20-Jun-09 9:26
Coffer20-Jun-09 9:26 
GeneralRe: Latitude/Longitude Pin
Mark Gray25-Nov-09 11:51
Mark Gray25-Nov-09 11:51 
GeneralRe: Latitude/Longitude Pin
MichaelCameron196128-Sep-11 23:51
MichaelCameron196128-Sep-11 23:51 
GeneralSome wrong values Pin
Onur Guzel4-Jan-09 0:28
Onur Guzel4-Jan-09 0:28 
GeneralRe: Some wrong values Pin
Onur Guzel23-May-10 0:20
Onur Guzel23-May-10 0:20 
QuestionHow do you change EXIF properties? Pin
abhi_here8-Sep-08 10:53
abhi_here8-Sep-08 10:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.