#include "stdafx.h"
#include "gdiplus.h"
#include "atlp_w_picpath.h"
using namespace Gdiplus;
#include
using namespace std;
GdiplusStartupInput gSDKdiplusStartupInput = 0;
ULONG_PTR gSDKdiplusToken = 0;
int GetEncoderClsidOwn(const WCHAR* format, CLSID* pClsid)
{
UINT num = 0; // number of p_w_picpath encoders
UINT size = 0; // size of the p_w_picpath encoder array in bytes
ImageCodecInfo* pImageCodecInfo = NULL;
GetImageEncodersSize(&num, &size);
if(size == 0)
return -1; // Failure
pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
if(pImageCodecInfo == NULL)
return -1; // Failure
GetImageEncoders(num, size, pImageCodecInfo);
for(UINT j = 0; j < num; ++j)
{
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
{
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j; // Success
}
}
free(pImageCodecInfo);
return -1; // Failure
}
void main()
{
GdiplusStartup(&gSDKdiplusToken, &gSDKdiplusStartupInput, NULL);
USES_CONVERSION;
FontFamily fontFamily(L"Arial");
float fontSize = 12*(float)abs(2);
Font font(&fontFamily, fontSize, FontStyleBold, UnitPixel);
SolidBrush blackBrush(Color(0, 0, 0));
PointF pointF(1, 1);
CLSID encoderClsid;
GetEncoderClsidOwn(L"p_w_picpath/jpeg", &encoderClsid);
string filename;
WCHAR wfilename[MAX_PATH];
for(int i=0;i<20;i++)
{
filename = "out_";
char str[4];
itoa(i, str, 10);
filename = filename+str;
filename=filename+".jpg";
memset(wfilename,0,MAX_PATH);
wcscpy(wfilename, T2W(filename.c_str()) );
Bitmap bmp(L"sample.jpg");
Graphics g(&bmp);
g.DrawString(wfilename, -1, &font, pointF, &blackBrush);
bmp.Save(wfilename,&encoderClsid);
printf("%d\n",i);
}
GdiplusShutdown(gSDKdiplusToken);
}