如何利用vc代码读取jpg文件的“作者”等属性值。如下图中的wang ming我参考了http://topic.csdn.net/u/20090304/22/e3438075-fa20-4b0c-add4-7b5cf30394ee.html,里面提到调用shell的方法获取“作者”信息,但是没有成功。有哪位知道,请指点下。
解决方案 »
- 我写了一堆画圆和填充的代码 但是报错说什么不需要三个 教教我那 谢谢
- VS2008工程问题
- vs2005一个莫名的错误:error PRJ0002 : 错误的结果 128(从“D:\Program Files\Microsoft Visual Studio 8.0\VC\bin\cl.exe”返回)
- 如何实现autocad的线文件从地方坐标系到北京54坐标系的转换
- 我用mfc编写了一个ocx控件,为什么在网页中显示不了?
- Format输出的问题:如何指定输出数字的位数(不足用0补充)。
- 那位大哥有图像压缩的源码,急需
- 如何忽略第三方提供的OBJ中指定的PDB路径
- 对不起,借地方发一贴 ??????关于多操作系统的安装问题???????
- mfc 界面线程怎么安全退出
- 问一个windows系统的注册表设置的问题。
- 学习中间件技术原理与应用 这门课程有什么用?
#include <stdio.h>
#include <iostream>
#include <locale.h>#ifndef ULONG_PTR
#define ULONG_PTR unsigned long*
#endif
#include <GdiPlus.h>
using namespace Gdiplus;
#pragma comment(lib,"gdiplus.lib")// Helper function
void PropertyTypeFromWORD(WORD index, WCHAR* string, UINT maxChars)
{
WCHAR* propertyTypes[] = {
L"Nothing", // 0
L"PropertyTagTypeByte", // 1
L"PropertyTagTypeASCII", // 2
L"PropertyTagTypeShort", // 3
L"PropertyTagTypeLong", // 4
L"PropertyTagTypeRational", // 5
L"Nothing", // 6
L"PropertyTagTypeUndefined", // 7
L"Nothing", // 8
L"PropertyTagTypeSLONG", // 9
L"PropertyTagTypeSRational"}; // 10
wcsncpy(string, propertyTypes[index], maxChars);
}int main()
{
setlocale(LC_ALL,"chs");
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
while(true)
{
WCHAR szName[1024];
printf("请输入一个图像文件的名称:\n");
if(!std::wcin.getline(szName,sizeof(szName)/sizeof(WCHAR)))
return -1;
UINT size = 0;
UINT count = 0;
#define MAX_PROPTYPE_SIZE 128
WCHAR strPropertyType[MAX_PROPTYPE_SIZE] = L""; Bitmap* bitmap = new Bitmap(szName);
if(Ok != bitmap->GetLastStatus())
{
delete bitmap;
printf("图像文件打开失败!\n");
continue;
}
bitmap->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\n", size); PropertyItem* pPropBuffer = (PropertyItem*)malloc(size);
// Get the array of PropertyItem objects.
bitmap->GetAllPropertyItems(size, count, pPropBuffer);
// For each PropertyItem in the array, display the id, type, and length.
// For each PropertyItem in the array, display the id, type, and length.
for(UINT j = 0; j < count; ++j)
{
// Convert the property type from a WORD to a string.
PropertyTypeFromWORD(
pPropBuffer[j].type, strPropertyType, MAX_PROPTYPE_SIZE); printf("Property Item %d\n", j);
printf(" id: 0x%X\n", pPropBuffer[j].id);
wprintf(L" type: %s\n", strPropertyType);
printf(" length: %d bytes\n", pPropBuffer[j].length);
if(PropertyTagTypeASCII == pPropBuffer[j].type)
printf(" value: %s\n\n", pPropBuffer[j].value);
else if((0x9C9D == pPropBuffer[j].id)
&& (PropertyTagTypeByte == pPropBuffer[j].type))
wprintf(L" 作者: %s\n\n", pPropBuffer[j].value);
else
printf("\n");
} free(pPropBuffer);
delete bitmap;
}
GdiplusShutdown(gdiplusToken);
return 0;
}
典型运行结果如下:
There are 3 pieces of metadata in the file.
The total size of the metadata is 324 bytes.Property Item 0
id: 0x9C9D
type: PropertyTagTypeByte
length: 20 bytes
作者: Haty_MiaoProperty Item 1
id: 0x5090
type: PropertyTagTypeShort
length: 128 bytesProperty Item 2
id: 0x5091
type: PropertyTagTypeShort
length: 128 bytes
/////////////////
其中Property Item 0中的作者就是你要的~~
还想问下hastings,关于gdiplus获取图片元数据这部分的文档能否提供一下?想知道具体每个属性所对应的id分别是多少,就像楼上的“作者”这个属性的id为0x9C9D
谢谢!
不过没有id为0x9C9D这一项,这个也是我猜的。 - -