Archived:Manipulating the EXIF data of a JPEG file using Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Article Metadata
Code ExampleCompatibility
Platform(s): S60 3rd Edition, S60 3rd Edition FP1
S60 3rd Edition FP1
S60 3rd Edition (initial release)
Created: User:Technical writer 2 (November 22, 2006; updated March 25, 2008)
Last edited: hamishwillee (01 Jul 2012)


Manipulating the EXIF data of a JPEG file


The CJPEGExifEncoder class is a part of Symbian's Image Conversion Library API and as the documentation clearly states, this API is not a part of the SDK (the required header file ICLExif.h is missing).
The EXIF API was introduced in S60 3rd Edition SDK and it consists of the following classes: CExifModify, CExifRead, CExifTag, and TExifTagInfo.
The code sequence below exemplifies how the above mentioned API can be used to update or create the EXIF data of a given *.jpg file.


 void CTest::UpdateExifL( const TFileName& aFileName )
RFs fsSession;
RFile rFile;
TInt fileSize = 0;
HBufC8* buff = NULL;
HBufC8* newExif = NULL;
CExifModify* modify = NULL;
TBool createNew = EFalse;
// Connect to the fileserver
User::LeaveIfError(rFile.Open( fsSession,
EFileRead ));
rFile.Size( fileSize );
buff = HBufC8::NewLC( fileSize);
TPtr8 tprBuff = buff->Des();
// Will leave with KErrCorrupt if EXIF info not valid
TRAPD( error, modify = CExifModify::NewL( tprBuff ) );
if(error == KErrCorrupt)
modify = CExifModify::NewL( tprBuff,
CExifModify::ECreate );
createNew = ETrue;
CleanupStack::PushL( modify );
// New EXIF structure must have all mandatory fields.
// See http://www.exif.org/Exif2-2.PDF
if( createNew )
// Modify particular fields as needed
modify->SetImageDescriptionL( _L8("TestS60App") );
modify->SetMakeL( _L8("Nokia S60") );
// WriteDataL will leave with KErrNotReady if
// mandatory tags not present
TRAP(error, newExif = modify->WriteDataL(tprBuff) );
if( error != KErrNotReady )
User::LeaveIfError( error );
if( error == KErrNone )
// Write valid EXIF structure
User::LeaveIfError(rFile.Replace( fsSession,
EFileWrite ));
rFile.Write( *newExif );
CleanupStack::PopAndDestroy( newExif );
// Do nothing if EXIF structure is incomplete
// Destroy loaded resources from the cleanup stack
// (modify, buff, fsSession)
CleanupStack::PopAndDestroy( 3, &fsSession );

An example project for modifying the EXIF data by adding geotags to images can be found File:GeoTagging Example.zip.

This page was last modified on 1 July 2012, at 15:23.
74 page views in the last 30 days.