Ever wanted to generate "on the heap" images on your web server and send them to the client? It is now possible to do it in your ISAPI extension in just 2 lines of code (well almost).
In fact, this article presents a helper class, to be used in an MFC ISAPI extension that writes GDI+ images to the client browser. All you have to do is to load or generate the GDI+ image!
In this article I will suppose that:
- The reader has basic knowledge of GDI+. Here are some nice introductory articles on the CodeProject on this topic: GDI+ section.
- The reader has basic knowledge of MFC ISAPI extension. Here are some nice introductory articles on the CodeProject on this topic:
The rendering pipe is encapsulated in the
Note that with this method, there is no need to create temporary files on disk since they are directly written to the memory (
The use of the class is straight forward: build a
CGDIpISAPI object and call
void CHttpServerDerviedClass::Default( CHttpServerContext* pCtxt)
using namespace Gdiplus;
CGDIpISAPI renderer( this, pCtxt, &bitmap );
You can choose the image type (PNG, JPEG, BMP or TIFF). There is an
enum for the available codecs. You can also customize the quality for the PNG and JPEG files. It must be between 0 and 100.
All these options can be set at the construction or by setters.
Do not forget to initialize and de-initialize GDI+. I'm using a helper class for that:
CGDIpInitializer. It's use is self-explaining.
class CMyExtension : public CHttpServer
BOOL CMyExtension::GetExtensionVersion(HSE_VERSION_INFO* pVer)
BOOL CMyExtension::TerminateExtension(DWORD dwFlags)
What not to do...
- When writing an image, do not write any text... So forget about
The demo projects is a MFC ISAPI extension (for VC7) that illustrates different options of
CGDIpISAPI. Note that you also use this class in VC6.
You can test all the features by viewing the test.html file. Of course, before that you must compile the project, put the DLL in your script directory, etc... Below is a screenshot of the output of test.htm:
- MSDN Sample: PINBALL
- What an ISPAPI extension is? by Mehdi Mousavi
- 4 October 2002
- Fixed a small bug in the
CGDIpISAPI class (was always exporting as JPEG) <!--
- Added live demo! See the image, it is generated using the ISAPI extension...
(look at the HTML source) -->