Click here to Skip to main content
15,881,881 members
Articles / Desktop Programming / MFC
Article

Cexif

Rate me:
Please Sign up or sign in to vote.
4.65/5 (35 votes)
15 Mar 20031 min read 195.3K   7.9K   102   29
A small class to read EXIF data from JPEG images.

Sample Image - cexif.png

Introduction

Cexif is a small class to read the EXIF data stored in JPEG images, normally generated by digital cameras.

The code is based on Jhead, written by Matthias Wandel. Jhead offers a lot of switches to parse an image with EXIF tags, but it's plain C. I simply rearranged the functions and the global variables into a simple class.

Another useful article on this topic is here [^], with a bit of details on the EXIF structure. The official document for the "Digital Still Camera Image File Format Standard (Exchangeable image file format for Digital Still Cameras: Exif) Version 2.1" can be downloaded from http://www.bbs-informatique.fr/pdf/photo/Exif_2-1.pdf [^].

You can find some EXIF images at http://www.exif.org/samples.html

Using the code

You can use this class in 2 ways. The simplest is:

Cexif exif;
exif.DecodeExif(hFile);

where hFile is a valid file handle. If the file contains EXIF data, exif.m_exifinfo->IsExif is true, and you can read the fields in exif.m_exifinfo to create a report. The second way is:

EXIFINFO m_exifinfo;
memset(&m_exifinfo,0,sizeof(EXIFINFO));
Cexif exif(&m_exifinfo);
exif.DecodeExif(hFile);

In this case the result is stored in the variable m_exifinfo, and you can delete the exif object without losing the EXIF data.

More EXIF tags

typedef struct tag_ExifInfo {
    char  Version      [5];
    char  CameraMake   [32];
    char  CameraModel  [40];
    char  DateTime     [20];
    int   Height, Width;
    int   Orientation;
    int   IsColor;
    int   Process;
    int   FlashUsed;
    float FocalLength;
    float ExposureTime;
    float ApertureFNumber;
    float Distance;
    float CCDWidth;
    float ExposureBias;
    int   Whitebalance;
    int   MeteringMode;
    int   ExposureProgram;
    int   ISOequivalent;
    int   CompressionLevel;
    float FocalplaneXRes;
    float FocalplaneYRes;
    float FocalplaneUnits;
    float Xresolution;
    float Yresolution;
    float ResolutionUnit;
    float Brightness;
    char  Comments[MAX_COMMENT];
    unsigned char * ThumbnailPointer;
    unsigned ThumbnailSize;
    bool  IsExif;
} EXIFINFO;

If needed, the EXIFINFO structure can be extended to read more tags.

  1. Declare a new field in the EXIFINFO structure (example: float ExposureTime;)
  2. Define a new tag in exif.cpp (example: #define TAG_EXPOSURETIME 0x829A).
  3. Add a new case in the ProcessExifDir function.

Example:

case TAG_EXPOSURETIME:
m_exifinfo->ExposureTime = (float)ConvertAnyFormat(ValuePtr, Format);
break;

ConvertAnyFormat converts automatically the value stored in the tag.

To Do

  • Cexif::EncodeExif : to append the EXIF data into a standard JPEG image.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralDear sir, Pin
Member 1161192127-Apr-15 4:42
Member 1161192127-Apr-15 4:42 
QuestionAbout License Pin
Dejavuh14-May-14 17:17
Dejavuh14-May-14 17:17 
AnswerRe: About License Pin
Davide Pizzolato15-May-14 6:08
Davide Pizzolato15-May-14 6:08 
GeneralRe: About License Pin
Dejavuh15-May-14 13:21
Dejavuh15-May-14 13:21 
QuestionWrite exif Pin
Michael Riosa Nielsen13-Sep-12 6:35
Michael Riosa Nielsen13-Sep-12 6:35 
GeneralError fix Pin
yury_i21-Jan-10 4:49
yury_i21-Jan-10 4:49 
GeneralRe: Error fix Pin
Damir Valiulin7-May-10 20:16
Damir Valiulin7-May-10 20:16 
GeneralMy vote of 1 Pin
arkilisx19-Oct-09 4:48
arkilisx19-Oct-09 4:48 
GeneralMaking the demo work on Visual Studio 2008 under Vista Pin
stormydaniels30-Nov-08 11:28
stormydaniels30-Nov-08 11:28 
GeneralRe: Making the demo work on Visual Studio 2008 under Vista Pin
JIAOZONGLU18-Oct-11 23:11
JIAOZONGLU18-Oct-11 23:11 
GeneralDemo program doesn't read EXIF data from Pentax K100D Pin
Nico Cuppen14-Oct-08 5:33
Nico Cuppen14-Oct-08 5:33 
GeneralRe: Demo program doesn't read EXIF data from Pentax K100D Pin
Davide Pizzolato14-Oct-08 12:46
Davide Pizzolato14-Oct-08 12:46 
GeneralEXIF GPS tags Pin
andycarr19-Jan-08 0:32
andycarr19-Jan-08 0:32 
Generalcomments in JPEG files Pin
Martin081531-May-07 2:26
professionalMartin081531-May-07 2:26 
GeneralIMC INFO Pin
AndE0026-Feb-05 4:42
AndE0026-Feb-05 4:42 
GeneralOrientation Pin
TeaShirt26-Aug-04 15:43
TeaShirt26-Aug-04 15:43 
GeneralRe: Orientation Text Descriptions Pin
jmeaux14-Aug-05 8:23
jmeaux14-Aug-05 8:23 
QuestionHow to make a non-Exif jpg an Exif jpg? Pin
cjjj11-Nov-03 21:22
cjjj11-Nov-03 21:22 
AnswerRe: How to make a non-Exif jpg an Exif jpg? Pin
cjjj20-Nov-03 0:29
cjjj20-Nov-03 0:29 
AnswerRe: How to make a non-Exif jpg an Exif jpg? Pin
JIAOZONGLU18-Oct-11 23:14
JIAOZONGLU18-Oct-11 23:14 
GeneralCan't Read Fujifilm EXIF Pin
Richard Collins21-Oct-03 3:41
Richard Collins21-Oct-03 3:41 
Hi. The Cexif class (16/Mar/2003) works fine on Olympus .jpg files but not on those from a Fuji FinePix camera. The format in the Fuji file is Exif II - I guess it should work. The smallest Fuji file I have is 500 KB - I can send if you want it. Thanks.

RC
GeneralRe: Can't Read Fujifilm EXIF Pin
Davide Pizzolato25-Oct-03 6:03
Davide Pizzolato25-Oct-03 6:03 
GeneralCexif::EncodeExif Pin
David Horner18-Aug-03 18:37
David Horner18-Aug-03 18:37 
GeneralRe: Cexif::EncodeExif Pin
Davide Pizzolato18-Aug-03 21:08
Davide Pizzolato18-Aug-03 21:08 
GeneralExport Exif data Pin
BengCésar9-Jul-03 2:01
BengCésar9-Jul-03 2:01 

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.