|
|
第一次写文章就遇到了毁灭性的打击, 我痛恨着拙劣的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里相关的头文件,请参见下面的注意。
注意:要想把这个程序运行成功,要经过下面的一些准备工作,这是我试验得来的,知其然不知其所以然,请懂的人指点。 第一步: 从BCB安装的文件夹下的include文件夹里把所有gdiplus开头的头文件全都拷到你的工程文件夹(就是上面那个c++程序所在的文件夹),因为需要对它们作小小的改动。注意不要使用ms sdk里的头文件和lib。
第二步: 把GdiplusGraphics.h的第33行改为: return new Graphics(hdc,0);(这样改应该有潜在的错误,但没有发现。) 在GdiplusTypes.h的第87、88行插入下面两行: REAL min(REAL a, REAL b){return a<=b?a:b;} REAL max(REAL a, REAL b){return a>=b?a:b;}
第三步: 从MS的网站下载gdiplus.dll,(网址:http://www.microsoft.com/downloads/details.aspx?FamilyID=6a63ab9c-df12-4d41-933c-be590feaa05a&DisplayLang=en ) 运行BCB的bin文件夹里的 implib gdiplus gdiplus.dll生成gdiplus.lib 把gdiplus.lib放在工程文件夹内,用Shift+F11把gdiplus.lib加入到工程。 (或者使用#pragma comment(lib, "gdiplus.lib")语句) 注意不能使用ms sdk里的lib。
然后就可以了。
其他请参见: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdicpp/GDIPlus/usingGDIPlus/usingimagesbitmapsandmetafiles/readingandwritingmetadata.asp
Kevin Pisarsky有一篇介绍delphi下获取metadata的文章,我不知道名字, 但有个关键词是:EXIF information 你可以在网上检索一下。
|
|