中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > 综合其它
用gdi+获取图像的附加信息(metadata)--如jpg照片的标题,相机,曝光时间等
作者:未知 时间:2005-07-27 23:25 出处:CSDN 责编:chinaitpower
              摘要:用gdi+获取图像的附加信息(metadata)--如jpg照片的标题,相机,曝光时间等
第一次写文章就遇到了毁灭性的打击,
我痛恨着拙劣的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
你可以在网上检索一下。



关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有