資源簡介
多媒體技術實驗三-EXIF讀寫

代碼片段和文件信息
/*
?*?File: exif.cpp
?*?Purpose: cpp?EXIF?reader
?*?16/Mar/2003?
?*?based?on?jhead-1.8?by?Matthias?Wandel?
?*/
#include?“exif.h“
////////////////////////////////////////////////////////////////////////////////
Cexif::Cexif(EXIFINFO*?info)
{
if?(info)?{
m_exifinfo?=?info;
freeinfo?=?false;
}?else?{
m_exifinfo?=?new?EXIFINFO;
memset(m_exifinfo0sizeof(EXIFINFO));
freeinfo?=?true;
}
m_szLastError[0]=‘\0‘;
ExifImageWidth?=?MotorolaOrder?=?0;
SectionsRead=0;
memset(&Sections?0?MAX_SECTIONS?*?sizeof(Section_t));
}
////////////////////////////////////////////////////////////////////////////////
Cexif::~Cexif()
{
for(int?i=0;i if?(freeinfo)?delete?m_exifinfo;
}
////////////////////////////////////////////////////////////////////////////////
bool?Cexif::DecodeExif(FILE?*?hFile)
{
????int?a;
????int?HaveCom?=?0;
????a?=?fgetc(hFile);
????if?(a?!=?0xff?||?fgetc(hFile)?!=?M_SOI){
????????return?0;
????}
????for(;;){
????????int?itemlen;
????????int?marker?=?0;
????????int?lllh?got;
????????unsigned?char?*?Data;
????????if?(SectionsRead?>=?MAX_SECTIONS){
strcpy(m_szLastError“Too?many?sections?in?jpg?file“);
return?0;
????????}
????????for?(a=0;a<7;a++){
????????????marker?=?fgetc(hFile);
????????????if?(marker?!=?0xff)?break;
????????????if?(a?>=?6){
????????????????printf(“too?many?padding?unsigned?chars\n“);
????????????????return?0;
????????????}
????????}
????????if?(marker?==?0xff){
????????????//?0xff?is?legal?padding?but?if?we?get?that?many?something‘s?wrong.
????????????strcpy(m_szLastError“too?many?padding?unsigned?chars!“);
return?0;
????????}
????????Sections[SectionsRead].Type?=?marker;
????????//?Read?the?length?of?the?section.
????????lh?=?fgetc(hFile);
????????ll?=?fgetc(hFile);
????????itemlen?=?(lh?<8)?|?ll;
????????if?(itemlen?2){
????????????strcpy(m_szLastError“invalid?marker“);
return?0;
????????}
????????Sections[SectionsRead].Size?=?itemlen;
????????Data?=?(unsigned?char?*)malloc(itemlen);
????????if?(Data?==?NULL){
????????????strcpy(m_szLastError“Could?not?allocate?memory“);
return?0;
????????}
????????Sections[SectionsRead].Data?=?Data;
????????//?Store?first?two?pre-read?unsigned?chars.
????????Data[0]?=?(unsigned?char)lh;
????????Data[1]?=?(unsigned?char)ll;
????????got?=?fread(Data+2?1?itemlen-2hFile);?//?Read?the?whole?section.
????????if?(got?!=?itemlen-2){
????????????strcpy(m_szLastError“Premature?end?of?file?“);
return?0;
????????}
????????SectionsRead?+=?1;
????????switch(marker){
????????????case?M_SOS:???//?stop?before?hitting?compressed?data?
????????????????//?If?reading?entire?image?is?requested?read?the?rest?of?the?data.
????????????????/*if?(ReadMode?&?READ_IMAGE){
????????????????????int?cp?ep?size;
?????????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-12-26?21:30??EXIF\
?????文件???????22496??2018-12-26?20:26??EXIF\ExifTest.aps
?????文件????????1285??2018-12-26?20:26??EXIF\ExifTest.cpp
?????文件????????4277??2003-03-16?22:19??EXIF\ExifTest.dsp
?????文件????????1206??2018-12-26?20:26??EXIF\ExifTest.h
?????文件????????4447??2003-03-16?21:49??EXIF\ExifTest.rc
?????文件?????????882??2017-03-14?22:13??EXIF\ExifTest.sln
?????文件????????8042??2018-12-26?20:23??EXIF\ExifTest.vcxproj
?????文件????????2059??2018-12-26?20:34??EXIF\ExifTest.vcxproj.filters
?????文件?????????149??2018-12-26?20:34??EXIF\ExifTest.vcxproj.user
?????文件???????10248??2018-12-26?20:44??EXIF\ExifTestDlg.cpp
?????文件????????1516??2018-12-26?20:26??EXIF\ExifTestDlg.h
?????目錄???????????0??2018-12-26?21:30??EXIF\RES\
?????文件????????1078??2003-03-16?21:47??EXIF\RES\ExifTest.ico
?????文件?????????400??2003-03-16?21:47??EXIF\RES\ExifTest.rc2
?????文件?????????550??2018-12-26?20:26??EXIF\Resource.h
?????文件?????????212??2018-12-26?20:27??EXIF\StdAfx.cpp
?????文件????????1001??2018-12-26?20:26??EXIF\StdAfx.h
?????文件???????27936??2018-12-26?20:26??EXIF\exif.cpp
?????文件????????3482??2018-12-26?20:26??EXIF\exif.h
?????文件?????1174016??2018-12-26?21:25??實驗三-王玉峰-EXIF讀寫-20161745.doc
- 上一篇:AG35 AT指令
- 下一篇:QT利用SMTP發送郵件Demo
評論
共有 條評論