C++ 为什么这段代码不能将元数据设置为tif图像,但可以将元数据设置为jpg?
我已经实现了本文中的代码: 将元数据保存到jpg时,它工作得很好,但当我保存到tif时,却没有得到元数据 问题是什么?我如何解决 此代码可以向jpg图像添加新元数据:C++ 为什么这段代码不能将元数据设置为tif图像,但可以将元数据设置为jpg?,c++,jpeg,gdi+,tiff,exif,C++,Jpeg,Gdi+,Tiff,Exif,我已经实现了本文中的代码: 将元数据保存到jpg时,它工作得很好,但当我保存到tif时,却没有得到元数据 问题是什么?我如何解决 此代码可以向jpg图像添加新元数据: #include <windows.h> #include <gdiplus.h> #include <stdio.h> using namespace Gdiplus; INT main() { // Initialize <tla rid="tla_gdiplus"/>.
#include <windows.h>
#include <gdiplus.h>
#include <stdio.h>
using namespace Gdiplus;
INT main()
{
// Initialize <tla rid="tla_gdiplus"/>.
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
Status stat;
CLSID clsid;
char propertyValue[] = "Fake Photograph";
Bitmap* bitmap = new Bitmap(L"FakePhoto.jpg");
PropertyItem* propertyItem = new PropertyItem;
// Get the CLSID of the JPEG encoder.
GetEncoderClsid(L"image/jpeg", &clsid);
propertyItem->id = PropertyTagImageTitle;
propertyItem->length = 16; // string length including NULL terminator
propertyItem->type = PropertyTagTypeASCII;
propertyItem->value = propertyValue;
bitmap->SetPropertyItem(propertyItem);
stat = bitmap->Save(L"FakePhoto2.jpg", &clsid, NULL);
if(stat == Ok)
printf("FakePhoto2.jpg saved successfully.\n");
delete propertyItem;
delete bitmap;
GdiplusShutdown(gdiplusToken);
return 0;
}
但是这个代码不起作用:
#include <windows.h>
#include <gdiplus.h>
#include <stdio.h>
using namespace Gdiplus;
INT main()
{
// Initialize <tla rid="tla_gdiplus"/>.
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
Status stat;
CLSID clsid;
char propertyValue[] = "Fake Photograph";
Bitmap* bitmap = new Bitmap(L"FakePhoto.jpg");
PropertyItem* propertyItem = new PropertyItem;
// Get the CLSID of the JPEG encoder.
GetEncoderClsid(L"image/tiff", &clsid);
propertyItem->id = PropertyTagImageTitle;
propertyItem->length = 16; // string length including NULL terminator
propertyItem->type = PropertyTagTypeASCII;
propertyItem->value = propertyValue;
bitmap->SetPropertyItem(propertyItem);
stat = bitmap->Save(L"FakePhoto2.tif", &clsid, NULL);
if(stat == Ok)
printf("FakePhoto2.jpg saved successfully.\n");
delete propertyItem;
delete bitmap;
GdiplusShutdown(gdiplusToken);
return 0;
}
不同之处在于解码器和图像名称。为什么不起作用?请提供更多详细信息。除非您显示正在使用的代码,否则没有人可以回答您的问题。代码在我添加到问题的链接上的示例中,但我将在此处复制代码。我很高兴您发布了代码,因为您提供的链接没有具体显示您正在添加的元数据。TIFF和JPEG不一定支持相同的标记,而且在编写TIFF时,Microsoft的实现似乎没有正确实现PropertyTagImageTitle。也许您应该尝试使用另一个PropertyTag,看看它是否支持TIFF。顺便说一句,TIFF标签中没有ImageTitle这样的东西。请参阅此处以获取参考:事实上,我正在将GPS数据添加到jpg中,它可以工作,但不会添加到tiff中。tiff支持GPS exif元数据吗?有tiff GPS标记,但Microsoft可能没有在tiff中实现它们。出于这个原因以及更多原因,我编写了自己的图像库,这样我就不必希望微软能够正确地支持标准。