Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 06:17, 25 March 2008.

TSS000471 - Manipulating the EXIF data of a JPEG file

From Forum Nokia Wiki


ID TSS000471 Creation date November 22, 2006; updated March 25, 2008
Platform S60 3rd Edition, S60 3rd Edition FP1 Devices  
Category Symbian C++ Subcategory  

Description

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.


Solution

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(fsSession.Connect());
  CleanupClosePushL(fsSession);
  User::LeaveIfError(rFile.Open( fsSession, 
                                 aFileName, 
                                 EFileRead ));
  
  rFile.Size( fileSize );
  buff = HBufC8::NewLC( fileSize);
  TPtr8 tprBuff = buff->Des();
  rFile.Read(tprBuff);
  rFile.Close();
  
  // 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 )
    {
    CreateMandatoryTags(*modify);
    }
  
  // 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 )
    {
    CleanupStack::PushL(newExif);
    // Write valid EXIF structure
    User::LeaveIfError(rFile.Replace( fsSession,
                                      aFileName,
                                      EFileWrite ));
    rFile.Write( *newExif );
    rFile.Close();
    CleanupStack::PopAndDestroy( newExif );
    }
  else
    {
    // 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 here.

Related Discussions
Thread Thread Starter Forum Replies Last Post
Memory Full niraj_gandhi Mobile Java General 6 2007-05-18 11:31
photo + metadata = one file DrivingMobileInnovation Python 16 Yesterday 04:56
jpeg or bmp from mif Yuriy Yavorsky General Symbian C++ 8 2007-08-31 15:57
The encoding methods? xulx2007 General Messaging 0 2006-03-13 10:15
SMS reading Problem mateen_maldar General Messaging 3 2005-12-30 15:46
 
Powered by MediaWiki