×
Namespaces

Variants
Actions

如何处理JPEG文件中的EXIF数据

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

文章
hoolee 在 18 Feb 2008 创建
最后由 hamishwillee 在 15 Dec 2011 编辑
  • 开发伙伴平台:

S60 3rd Edition, S60 3rd Edition FP1


  • 详细描述

CJPEGExifEncoder类是Symbian图形转换库API中的一部分。但它在现有SDK中无法找到(缺少所需要的ICLExif.h文件)


EXIFAPI在S60第三版SDK中有所介绍,它包括下列类CExifModify, CExifRead, CExifTag和TExifTagInfo.


下列代码示例展示了如何利用上面相关的API从*.jpg文件中更新或生成EXIF数据

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;
 
// Connects a client process 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();
 
// NewL 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
 
CleanupStack::PopAndDestroy(3, &fsSession); // modify, buff, fsSession
 
}
This page was last modified on 15 December 2011, at 08:41.
24 page views in the last 30 days.