更新c+中的jpeg属性+;使用GDI+; 我想把C++中的一个JPEG图像的属性复制到另一个。因为我没有任何库,而且我正在windows上工作,所以我使用GDI+来实现这一点。 我的代码如下 void CopyJpegPrope
更新c+中的jpeg属性+;使用GDI+; <>我想把C++中的一个JPEG图像的属性复制到另一个。因为我没有任何库,而且我正在windows上工作,所以我使用GDI+来实现这一点。 我的代码如下更新c+中的jpeg属性+;使用GDI+; 我想把C++中的一个JPEG图像的属性复制到另一个。因为我没有任何库,而且我正在windows上工作,所以我使用GDI+来实现这一点。 我的代码如下 void CopyJpegPrope,c++,gdi+,exif,C++,Gdi+,Exif,更新c+中的jpeg属性+;使用GDI+; 我想把C++中的一个JPEG图像的属性复制到另一个。因为我没有任何库,而且我正在windows上工作,所以我使用GDI+来实现这一点。 我的代码如下 void CopyJpegProperties(string targetImageName,string sourceImageName) { CLSID m_clsid; EncoderParameters m_encoderPara
void CopyJpegProperties(string targetImageName,string sourceImageName)
{
CLSID m_clsid;
EncoderParameters m_encoderParameters;
UINT size;
UINT count;
int quality=100;
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR m_gdiplusToken;
// start GDI+
GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
{
// we are processing images inside a block to make sure that all of objects are deleted when GDI is shutdown.
// read source image properties
std::wstring wcSourceImageName=StringTools::StringToWString(sourceImageName);
Gdiplus::Bitmap sourceBitmap(wcSourceImageName.c_str());
sourceBitmap.GetPropertySize(&size, &count);
PropertyItem* pPropBuffer =(PropertyItem*)malloc(size);
sourceBitmap.GetAllPropertyItems(size, count, pPropBuffer);
// write to target image
std::wstring wcTargetImageName=StringTools::StringToWString(targetImageName);
Gdiplus::Bitmap targetBitmap(wcTargetImageName.c_str());
for(int i=0; i<count; i++)
{
targetBitmap.SetPropertyItem(&pPropBuffer[i]);
}
JpegTools::GetEncoderClsid(L"image/jpeg", &m_clsid);
m_encoderParameters.Count = 1;
m_encoderParameters.Parameter[0].Guid = EncoderQuality;
m_encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
m_encoderParameters.Parameter[0].NumberOfValues = 1;
m_encoderParameters.Parameter[0].Value = &quality;
Status stat = targetBitmap.Save(wcTargetImageName.c_str(), &m_clsid, &m_encoderParameters);
if(stat != Ok)
{
throw exception("Error in saving");
}
}
GdiplusShutdown(m_gdiplusToken);
}
void copyJPEG属性(字符串targetImageName、字符串sourceImageName)
{
CLSID m_CLSID;
编码器参数m_编码器参数;
单位尺寸;
单位计数;
int质量=100;
GdiplusStartupInput GdiplusStartupInput;
ULONG_PTR m_gdiplusToken;
//启动GDI+
GdiplusStartup(&m_gdiplusToken,&gdiplusStartupInput,NULL);
{
//我们正在处理块内的图像,以确保GDI关闭时删除所有对象。
//读取源图像属性
std::wstring wcSourceImageName=StringTools::StringToWString(sourceImageName);
Gdiplus::位图源位图(wcSourceImageName.c_str());
sourceBitmap.GetPropertySize(&size,&count);
PropertyItem*pPropBuffer=(PropertyItem*)malloc(大小);
GetAllPropertyItems(大小、计数、pPropBuffer);
//写入目标图像
std::wstring wcTargetImageName=StringTools::StringToString(targetImageName);
Gdiplus::位图targetBitmap(wcTargetImageName.c_str());
对于(int i=0;ii)如果您正在处理比XP更新的任何东西,那么可能是一个更好的选择,因为您不需要加载整个映像来操作元数据。另一方面,此代码不是异常安全的,如果引发异常,GDI+将不会关闭。@Mgetz谢谢,我将查看WIC,看看如何使用WIC实现这一点。