NO

Author Topic: Exif Info : Date Taken field  (Read 3375 times)

luca.crovato

  • Guest
Exif Info : Date Taken field
« on: April 06, 2012, 10:16:00 AM »
Dear All ,

I would like to know how I can get Exif information form a .jpg file ( especially the info about Date Taken field).

Thanks
Luca

CommonTater

  • Guest
Re: Exif Info : Date Taken field
« Reply #1 on: April 06, 2012, 05:35:21 PM »
The first thing you will need is a 3rd party libary that knows how to read .jpg header information.
For general information you can start at jpeg.org ... one of several libraries is at ijg.org
 
The next step is to integrate that library with Pelles C... Which may mean creating a project and compiling the library itself. 
 
Using the library is mostly a matter of making a folder and unpacking the files, then adding the libraries and headers to your project settings.  (DO NOT add these files directly into your Pelles C\Bin folders!)
 
Once you have that working you should be able to manipulate just about all header and file information by calling the various functions in the library.
 
Since you've posted this in the "Beginner" section, I should warn you this isn't exactly beginner coding... 3rd party libraries can raise all kinds of weird issues...
 
 

aardvajk

  • Guest
Re: Exif Info : Date Taken field
« Reply #2 on: April 07, 2012, 12:49:19 AM »
Assuming you just want the info and don't care how it comes about, it's built in to Windows as of Vista. along with other Exif bits and stuff for audio, documents, etc

Minimal example (I'm writing this in Visual Studio but it should work as is):
Code: [Select]
#include <windows.h>
#include <stdio.h>
#include <shobjidl.h>
#inculde <objbase.h>
#include <propkey.h>
#include <propvarutil.h>
#pragma comment(lib, "propsys.lib")
#pragma comment(lib, "ole32.lib")
#pragma comment(lib, "shell32.lib")

int wmain(int argc, wchar_t** argv)
{
    if(argc <= 1)
    {
        return wprintf(L"Please provide a jpeg file name with date taken exif field\n");
    }
    CoInitialize(NULL);
    IPropertyStore* pPropStore = NULL;
    HRESULT hr = SHGetPropertyStoreFromParsingName(argv[1], NULL, GPS_DEFAULT, IID_PPV_ARGS(&pPropStore));
    if(FAILED(hr))
    {
        CoUninitialize();
        return wprintf(L"Couldn't get prop store, error %#x\n", hr);
    }
    PROPVARIANT propVar = {0};
    hr = pPropStore->lpVtbl->GetValue(pPropStore, &PKEY_Photo_DateTaken, &propVar);
    if(FAILED(hr) || (V_VT(&propVar) == VT_EMPTY))
    {
        pPropStore->lpVtbl->Release(pPropStore);
        CoUninitialize();
        return wprintf(L"Didn't find a date taken property, error %#x\n", hr);
    }
    PWSTR pString = NULL;
    PropVariantToStringAlloc(&propVar, &pString);
    wprintf(L"Success! %ls was taken at %ls\n", argv[1], pString);
    CoTaskMemFree(pString);
    PropVariantClear(&propVar);
    pPropStore->lpVtbl->Release(pPropStore);
    CoUninitialize();
    return 0;
}
« Last Edit: April 07, 2012, 12:51:47 AM by aardvajk »