全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:3043
推到 Plurk!
推到 Facebook!

EXIF的讀取及修改

缺席
maped
一般會員


發表:13
回覆:19
積分:6
註冊:2008-10-06

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-02-21 00:56:14 IP:61.31.xxx.xxx 訂閱
Dear all,
想問問關於在JPEG中如何讀出EXIF及修改或增加EXIF TAG,
我在論壇中有找到幾篇相關文章,但是都只是點到為止,
想問一下有沒有實際的程式碼可以參考,或相關的library可以使用,
另外好像有個元件TExif
,不曉得有沒有人用過呢?

我有用過GDI 來做,但是有些資訊在picasa無法被讀取,
所以想看看有沒有其他方法來做。
環境:XP BCB 6.0

boss.tw
高階會員


發表:15
回覆:109
積分:194
註冊:2005-05-17

發送簡訊給我
#2 引用回覆 回覆 發表時間:2009-02-21 13:26:03 IP:122.116.xxx.xxx 訂閱
請參考
http://www.exiv2.org/#lib
or
http://delphi.ktop.com.tw/board.php?cid=168&fid=921&tid=30252


Exif規格
http://www.exif.org/specifications.html
方法一:
EXIF Tag Parsing Library Source 範例
http://sourceforge.net/project/showfiles.php?group_id=12272&release_id=132198


方法二:

試試這個範例吧!
資料來源:http://www.smalleranimals.com/isource/isourcesample_v2_2.htm
Get EXIF data from a JPG
EXIF data is stored in the JPGs created by most digital cameras. It contains information about the camera, the environment when the image was taken, the date, time, etc..


[code cpp]
UINT32 w,h,d;

// get the dimensions - we'll we really don't care about the dims.
// we just want to force a JPG marker read and this is the quickest way
// to do it.
HISSRC hSrc = ISOpenFileSource( pFilename );
ISGetJPGDims( hSrc, &w, &h, &d, NULL);
ISCloseSource( hSrc );

// loop over all JPEG_APPx markers
int ct=ISGetJPGInputMarkerCount();

for (int i=0; i < ct; i )
{
// get a JPG marker from ImgSoruce
HGLOBAL hData = NULL;
UINT32 len, type;
ISGetJPGInputMarker(i, &hData, &len, &type);

// only interested in JPEG_APP1 (#225)
if (type!=225)
{
GlobalFree(hData);
continue;
}
else
{
// start the EXIF parser
HGLOBAL hEXIF = ISEXIFInit((BYTE *)hData, len);

if (hEXIF!=NULL)
{
// get string with tag ID #271 (camera model)
// look in all subsections (1 | 2 | 4 | 8 = 15)
HGLOBAL hStr = NULL;
UINT32 uStrLen;
ISEXIFGetString(hEXIF, 272, 15, &hStr, &uStrLen);
if (hStr!=NULL)
{
// got it!
TRACE("model = %s\n", (char *)hStr);
GlobalFree(hStr);
}

// try the thumbnail
HGLOBAL hThumbnail = NULL;
UINT32 uTNLen = 0;
if (ISEXIFGetThumbnail(hEXIF, &hThumbnail, &uTNLen)==IS_ERR_OK)
{
// there is a thumbnail.

// what format is it?
int iFmt = 0;
HGLOBAL hStr = NULL;
UINT32 uStrLen;
ISEXIFGetString(hEXIF, 259, 8, &hStr, &uStrLen);
if (hStr!=NULL)
{
// got it!
TRACE("fmt = %s\n", (char *)hStr);
iFmt = atoi((char *)hStr);
GlobalFree(hStr);
}

if (iFmt==6) // 6 = JPG. 1 = TIFF, 0 = RGB, but most are JPG
{
// convet that to RGB
HISSRC hSrc = ISOpenMemorySource((BYTE *)hThumbnail, uTNLen);
HGLOBAL hImg = ISReadJPG(hSrc, &w, &h, 24);
ISCloseSource(hSrc);

if (hImg)
{
// draw it
CDC *pDC = GetDC();
ISDrawRGB( pDC->m_hDC, (BYTE *)hImg, w, h, 0, 0, w, h, NULL );
ReleaseDC(pDC);

GlobalFree(hImg);
}
}

// clean up
GlobalFree(hThumbnail);
}

// clean up
ISEXIFDestroy(hEXIF);
}
}

GlobalFree(hData);
}


[/code]
編輯記錄
boss.tw 重新編輯於 2009-02-21 13:27:47, 註解 無‧
boss.tw 重新編輯於 2009-02-21 13:31:26, 註解 無‧
maped
一般會員


發表:13
回覆:19
積分:6
註冊:2008-10-06

發送簡訊給我
#3 引用回覆 回覆 發表時間:2009-02-23 18:14:57 IP:210.243.xxx.xxx 訂閱
感謝 boss.tw 的回覆,
我已經使用兩套軟體 exiftool及 Exiv2 來加入GPS參數,
但是加入的GPS部分在Picasa3裡都無法被讀取,

另外你提到ImgSource裡面沒有GPS的部分,
想在請問大家還有沒有別的範例或程式可以參考的,
謝謝。
編輯記錄
maped 重新編輯於 2009-02-23 18:23:41, 註解 無‧
系統時間:2024-05-04 15:38:16
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!