保存的CImage给出了错误:标识符“ImageFormatJPEG”未定义

问题描述:

我使用Visual Studio 2012 我试图用一个的CImage保存为JPG如下:保存的CImage给出了错误:标识符“ImageFormatJPEG”未定义

theImage.Save(filePathAndName, Gdiplus::ImageFormatJPEG); 
截至 link to Microsoft example using CImage::Save所示

但是,Visual Studio中给出了错误:

Error: identifier "ImageFormatJPEG" is undefined 

为什么会出现这个错误?

注意,我已经包括以下内容:

#include <gdiplus.h> 

而且,我看着gdiplus.h,看到下面一行:

#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) 

封闭,除其他外,#include "GdiplusImaging.h"。 GdiplusImaging.h还采用

#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) 

封装,除其他外,

DEFINE_GUID(ImageFormatJPEG, 0xb96b3cae,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e); 

我认为这可能是造成问题的原因,但我还没有想通出来呢。

我不能直接指定使用

Gdiplus::ImageFormatJPEG 

为保存功能的第二个参数的图像格式。

然而,截至Microsoft's CImage::Save

If the guidFileType parameter is not included, the file name's file extension will be used to determine the image format.

指定于是,我做了以下内容:

char *filePathAndName = "C:\\Projects\\AcesHyAcceptanceTestScreenShot2.jpg"; 
theImage.Save(filePathAndName); 

到的CImage保存为JPEG格式。

如果有人知道的修复程序能够使用Gdiplus::ImageFormatJPEG请张贴的解决方案。

包括“atlimage.h”应该适合你。