|
|
用gdi+获取图像的附加信息(metadata)--如jpg照片的标题,相机,曝光时间等 |
|
|
作者:未知 来源:月光软件站 加入时间:2005-6-5 月光软件站 |
第一次写文章就遇到了毁灭性的打击, 我痛恨着拙劣的blog! 辛辛苦苦写到了凌晨四点,发表的时候没写文章摘要(damn it!),得到提示的时候竟然正文全没了! 我用的是该死的firefox,点击后退也没有任何作用,我怎么会一次也没有保存呢!见鬼了! 我不会抓内存,只有去死了。
BCB里还留了一点核心部分,请凑合着看吧。
#include <windows.h> #include "gdiplus.h" #include <stdio.h>
using namespace Gdiplus; //#pragma comment(lib, "gdiplus.lib")
INT main() { // Start up Gdi+ GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
Image* image = new Image(L"a.jpg"); UINT itemsize = 0; PropertyItem* item = NULL;
UINT size, count; image->GetPropertySize(&size, &count); printf("There are %d pieces of metadata in the file.\n", count); printf("The total size of the metadata is %d bytes.\n", size); // 获取设备制造商这一item,该属性的id为:PropertyItemEquipMake。 // 先获取该item的大小 itemsize = image->GetPropertyItemSize(PropertyTagEquipMake); // 依大小分配存放该item的内存 item = (PropertyItem*)malloc(itemsize); // 获取该item if ( Ok == image->GetPropertyItem(PropertyTagEquipMake, itemsize, item) ) { // 每个 PropertyItem 对象有四个属性,id,length,type,value。 printf("The length of the property item is %u.\n", item->length); printf("The data type of the property item is %u.\n", item->type); // 注意:对value的具体处理方法依type的不同而不同。 printf("The value of the property item is %s.\n", item->value); } else printf("Fail! :( \n");//想知道发生了什么可以参看:GdiplusTypes.h里的对Status的枚举 free(item);
// 获取曝光时间,该属性的id为:PropertyTagExifExposureTime。 itemsize = image->GetPropertyItemSize(PropertyTagExifExposureTime); item = (PropertyItem*)malloc(itemsize); if ( Ok == image->GetPropertyItem(PropertyTagExifExposureTime, itemsize, item) ) { printf("The length of the property item is %u.\n", item->length); printf("The data type of the property item is %u.\n", item->type); // 注意:对value的具体处理方法依type的不同而不同。 int* ptrLong = (int*)(item->value); printf("The exposure time is %d/%d.\n", ptrLong[0],ptrLong[1]); } else printf("Fail! :( \n"); free(item);
delete image; GdiplusShutdown(gdiplusToken);
system("pause"); return 0; }
该程序在Borland C++ Builder 6 下调试通过, 如果想用在vc下,需要borland 的include里相关的头文件,请参见下面的注意。
注意:
|
|
相关文章:相关软件: |
|