資源簡介
本實例基于VC++完成對JPEG圖片EXIF信息的提取以及縮略圖顯示,其中EXIF圖片的提取采用EXIF類完成,縮略圖的顯示部分由GDI+完成,在vs2005下編譯通過,代碼簡單,有注釋,非常適合學習和移植

代碼片段和文件信息
/*
?*?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;
???????????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????27955??2013-01-10?20:45??imageProcess\imageProcess\Exif.cpp
?????文件???????3480??2013-01-10?20:49??imageProcess\imageProcess\Exif.h
?????文件??????43192??2013-01-11?14:13??imageProcess\imageProcess\imageProcess.aps
?????文件???????2241??2013-01-10?18:01??imageProcess\imageProcess\imageProcess.cpp
?????文件????????526??2013-01-10?17:41??imageProcess\imageProcess\imageProcess.h
?????文件???????5627??2013-01-10?20:41??imageProcess\imageProcess\imageProcess.rc
?????文件???????5758??2013-01-10?20:48??imageProcess\imageProcess\imageProcess.vcproj
?????文件???????1427??2013-01-10?20:54??imageProcess\imageProcess\imageProcess.vcproj.LENOVO-B66F6293.user.user
?????文件???????1427??2013-01-22?09:33??imageProcess\imageProcess\imageProcess.vcproj.PC-20130105KLGD.Administrator.user
?????文件??????14539??2013-01-11?09:01??imageProcess\imageProcess\imageProcessDlg.cpp
?????文件????????988??2013-01-10?20:25??imageProcess\imageProcess\imageProcessDlg.h
?????文件???????2912??2013-01-06?15:50??imageProcess\imageProcess\ReadMe.txt
?????文件??????21630??2005-12-08?14:56??imageProcess\imageProcess\res\imageProcess.ico
?????文件????????368??2013-01-06?15:50??imageProcess\imageProcess\res\imageProcess.rc2
?????文件???????1005??2013-01-10?18:09??imageProcess\imageProcess\resource.h
?????文件????????145??2013-01-06?16:47??imageProcess\imageProcess\stdafx.cpp
?????文件???????2520??2013-01-10?20:54??imageProcess\imageProcess\stdafx.h
?????文件????????901??2013-01-06?15:50??imageProcess\imageProcess.sln
????..A..H.?????52224??2013-01-22?09:33??imageProcess\imageProcess.suo
?????文件??????73728??2013-01-22?09:32??imageProcess\release\imageProcess.exe
?????目錄??????????0??2013-01-22?09:30??imageProcess\imageProcess\res
?????目錄??????????0??2013-01-22?09:33??imageProcess\imageProcess
?????目錄??????????0??2013-01-22?09:33??imageProcess\release
?????目錄??????????0??2013-01-22?09:33??imageProcess
-----------?---------??----------?-----??----
???????????????262593????????????????????24
- 上一篇:C語言課程設計學生成績管理系統源碼文檔.rar
- 下一篇:簡單的停車場收費 c++
評論
共有 條評論