Click here to Skip to main content
Licence 
First Posted 15 Mar 2003
Views 117,098
Downloads 3,372
Bookmarked 90 times

Cexif

By Davide Pizzolato | 15 Mar 2003
A small class to read EXIF data from JPEG images.
2 votes, 6.1%
1
1 vote, 3.0%
2
2 votes, 6.1%
3
3 votes, 9.1%
4
25 votes, 75.8%
5
4.62/5 - 33 votes
3 removed
μ 4.46, σa 2.03 [?]

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

About the Author

Davide Pizzolato



Italy Italy

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralError fix Pinmemberyury_i5:49 21 Jan '10  
GeneralRe: Error fix PinmemberDamir Valiulin21:16 7 May '10  
GeneralMy vote of 1 Pinmemberarkilisx5:48 19 Oct '09  
GeneralMaking the demo work on Visual Studio 2008 under Vista PinmemberCodeGibbon12:28 30 Nov '08  
GeneralRe: Making the demo work on Visual Studio 2008 under Vista PinmemberJIAOZONGLU0:11 19 Oct '11  
GeneralDemo program doesn't read EXIF data from Pentax K100D PinmemberNico Cuppen6:33 14 Oct '08  
GeneralRe: Demo program doesn't read EXIF data from Pentax K100D PinsupporterDavide Pizzolato13:46 14 Oct '08  
GeneralEXIF GPS tags Pinmemberandycarr11:32 9 Jan '08  
Generalcomments in JPEG files PinmemberMartin08153:26 31 May '07  
Hello,
 
using Cexif I realized it is only possible to read comments from JPEG files if they contain EXIF information.
 
But a JPEG file containing only comments fails.
 
I just wanted to test, if Cexif is able to read more than one comment chunk from a JPEG file, so that it is possible to extract all probably existing comment chunks.
 
Ok - Perhabs, 4 years after the last article update, somebody can help a bit!
 
Best regards,
 
Martin
GeneralIMC INFO PinmemberAndE005:42 26 Feb '05  
GeneralOrientation PinmemberTeaShirt16:43 26 Aug '04  
GeneralRe: Orientation Text Descriptions Pinmemberjmeaux9:23 14 Aug '05  
QuestionHow to make a non-Exif jpg an Exif jpg? Pinmembercjjj22:22 11 Nov '03  
AnswerRe: How to make a non-Exif jpg an Exif jpg? Pinmembercjjj1:29 20 Nov '03  
AnswerRe: How to make a non-Exif jpg an Exif jpg? PinmemberJIAOZONGLU0:14 19 Oct '11  
GeneralCan't Read Fujifilm EXIF PinmemberRichard Collins4:41 21 Oct '03  
GeneralRe: Can't Read Fujifilm EXIF PinsupporterDavide Pizzolato7:03 25 Oct '03  
GeneralCexif::EncodeExif PinmemberDavid Horner19:37 18 Aug '03  
GeneralRe: Cexif::EncodeExif PinsupporterDavide Pizzolato22:08 18 Aug '03  
GeneralExport Exif data PinmemberBengCésar3:01 9 Jul '03  
GeneralRe: Export Exif data PinsupporterDavide Pizzolato8:58 14 Jul '03  
GeneralI can't read the exif format of my photo file PinmemberRousset de Pina0:39 23 Mar '03  
GeneralRe: I can't read the exif format of my photo file PinsupporterDavide Pizzolato0:45 23 Mar '03  
GeneralRe: I can't read the exif format of my photo file PinmemberRousset de Pina1:30 23 Mar '03  

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

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120210.1 | Last Updated 16 Mar 2003
Article Copyright 2003 by Davide Pizzolato
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid