#include "StdAfx.h"
#include "gdipexample.h"
#include "GDIpISAPI.h"
void CGdipExample::SetSize(int iWidth,int iHeight)
{
m_size = CSize( __max( 1, __min( 1024, iWidth)), __max( 1, __min( 1024, iHeight)) );
}
void CGdipExample::DrawStuff(Gdiplus::Image& image)
{
using namespace Gdiplus;
USES_CONVERSION;
CString str,str2;
if (!m_pServer || !m_pCtxt)
return;
DWORD dwBuffer=1024;
int w=image.GetWidth();
int h= image.GetHeight();
Graphics graphics(&image);
// Create a Pen object.
LinearGradientBrush white(
Point(0, 0),
Point(w,h),
Color(255, 255, 255), // opaque red
Color(220, 220, 220)); // opaque blue
LinearGradientBrush redyellow(
Point(0, 0),
Point(w,h),
Color(0,0,255,0), // opaque red
Color(200, 255, 255,0)); // opaque blue
SolidBrush blue(Color(0, 0, 50));
Pen black(Color(0, 0, 0), 3);
FontFamily fontFamily(L"Tahoma");
Font font(&fontFamily, 14, FontStyleRegular, UnitPixel);
graphics.FillRectangle(&white, 0,0,w, h);
graphics.FillRectangle(&redyellow, 5,5,50, h-10);
graphics.DrawRectangle(&black, 5,5,w-10, h-10);
str+="This image has been generated by GDI+ (on the server)\r\n and sent to your browser using an ISAPI extension.\r\n\r\n";
str+="Time/Date: "; str+=CTime::GetCurrentTime().Format("%b-%d-%Y, %H:%M:%S"); str+="\r\n";
m_pCtxt->GetServerVariable(_T("REMOTE_HOST"), str2.GetBufferSetLength(dwBuffer), &dwBuffer);
str2.ReleaseBuffer();
str+="Client adress: "; str+=str2; str+="\r\n";
str+="Type: "; str+=m_sImageType; str+="\r\n";
str2.Format("%dx%d",w, h);
str+="Size (pixels): "; str+=str2; str+="\r\n";
str+="Method: "; str+=m_pCtxt->m_pECB->lpszMethod; str+="\r\n";
str+="Coded by Jonathan de Halleux, dehalleux@auto.ucl.ac.be\r\n";
LPWSTR lpwz = A2W(str);
graphics.DrawString(lpwz, -1, &font, PointF((REAL)30, (REAL)30), &blue);
graphics.Flush( FlushIntentionFlush);
}
void CGdipExample::Render()
{
CSingleLock lock(&m_mutex);
lock.Lock();
if (lock.IsLocked())
{
Gdiplus::Bitmap bitmap(m_size.cx, m_size.cy);
DrawStuff(bitmap);
CGDIpISAPI gdip(m_pServer, m_pCtxt, &bitmap);
m_sImageType.MakeLower();
if (m_sImageType=="jpeg" || m_sImageType=="jpg")
gdip.SetImageType(CGDIpISAPI::ImageJPEG);
else if (m_sImageType=="bmp")
gdip.SetImageType(CGDIpISAPI::ImageBMP);
else
gdip.SetImageType(CGDIpISAPI::ImagePNG);
gdip.WriteImage();
lock.Unlock();
}
}