IonicWind Software

Aurora Compiler => Tips and Tricks => Topic started by: sapero on April 08, 2009, 07:45:13 AM

Title: Reading EXIF with gdiplus
Post by: sapero on April 08, 2009, 07:45:13 AM
This is a mini example of exif reader. Its purpose is to show only how to read it.
If you have any modern digital camera, probably you'll find it usefull.

All available properties are defined in GdiplusImaging.inc.
#include "windows.inc"
#include "shlwapi.inc"
#include "gdiplus.inc"

GdiplusStartupInput g_si; // here to skip ZeroMemory()

sub main()
{
INT_PTR gdiptoken;
g_si.GdiplusVersion = 1;
GdiplusStartup(&gdiptoken, &g_si, 0);

IStream *stream;
if (!SHCreateStreamOnFile(FILEREQUEST("open JPG",0,TRUE,"JPG files|*.jpg;*.jpeg||","jpg",OFN_EXPLORER), STGM_READ, &stream))
{
GpImage *img;
if (!GdipLoadImageFromStream(stream, &img))
{
// read exif properties

int size;
PropertyItem *pprop;
// camera model
if (!GdipGetPropertyItemSize(img, PropertyTagEquipModel, &size) && size)
{
pprop = new(byte, size);
if (!GdipGetPropertyItem(img, PropertyTagEquipModel, size, pprop))
{
// pprop->type = PropertyTagTypeASCII
MessageBox(0, "Camera Model: " + pprop->*(string)value, "");
}
delete pprop;
}

// image orientation
if (!GdipGetPropertyItemSize(img, PropertyTagOrientation, &size) && size)
{
pprop = new(byte, size);
if (!GdipGetPropertyItem(img, PropertyTagOrientation, size, pprop))
{
// pprop->type = PropertyTagTypeShort
MessageBox(0, "Orientation: " + str$(pprop->*(word)value), "");
}
delete pprop;
}

GdipDisposeImage(img);
}
stream->Release();
}
GdiplusShutdown(gdiptoken);
return 0;
}

By the way i'm looking for a picture with orientation other than ONE. Could you share?

I think I have what I just needed (http://www.exif.org/specifications.html):if (!GdipLoadImageFromStream(stream, &img))
{
int size;
if (!GdipGetPropertyItemSize(img, PropertyTagOrientation, &size) && size)
{
PropertyItem *pprop = new(byte, size);
if (!GdipGetPropertyItem(img, PropertyTagOrientation, size, pprop))
{
// array: RotateFlipType[value] 0, 0, 4, 2, 6, 7, 3, 5, 1
switch (pprop->*(word)value)
{
case 2: // The 0th row is at the visual top of the image, and the 0th column is the visual right-hand side.
GdipImageRotateFlip(img, RotateNoneFlipX);
case 3: // The 0th row is at the visual bottom of the image, and the 0th column is the visual right-hand side.
GdipImageRotateFlip(img, Rotate180FlipNone);
case 4: // The 0th row is at the visual bottom of the image, and the 0th column is the visual left-hand side
GdipImageRotateFlip(img, RotateNoneFlipY);
case 5: // The 0th row is the visual left-hand side of of the image, and the 0th column is the visual top.
GdipImageRotateFlip(img, Rotate90FlipY);
case 6: // The 0th row is the visual right -hand side of of the image, and the 0th column is the visual top.
GdipImageRotateFlip(img, Rotate270FlipNone);
case 7: // The 0th row is the visual right -hand side of of the image, and the 0th column is the visual bottom.
GdipImageRotateFlip(img, Rotate270FlipY);
case 8: // The 0th row is the visual left-hand side of of the image, and the 0th column is the visual bottom
GdipImageRotateFlip(img, Rotate90FlipNone);