Click here to Skip to main content
13,345,954 members (55,962 online)
Click here to Skip to main content
Add your own
alternative version


25 bookmarked
Posted 1 Oct 2002

Dynamically generating images in ISAPI extension using GDI+ with live demo

, 3 Oct 2002
Rate this:
Please Sign up or sign in to vote.
A class wrapper to write GDI+ images to the client browser using an ISAPI extension.



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:

Rendering pipe

The rendering pipe is encapsulated in the WriteImage function:

Note that with this method, there is no need to create temporary files on disk since they are directly written to the memory (hGlobal).


Basic use

The use of the class is straight forward: build a CGDIpISAPI object and call WriteImage:

void CHttpServerDerviedClass::Default( CHttpServerContext* pCtxt)
    // GDI+ namespace
    using namespace Gdiplus;

    // creating bitmap
    Bitmap bitmap(320,200);
    // drawing on this bitmap

    // sending bitmap to the browser
    CGDIpISAPI renderer( this, pCtxt, &bitmap );
    // sending image

Output options

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.

  • Setting BMP type
    renderer.SetImageType( CGDIpISAPI::ImageBMP);
  • Changing quality
    renderer.SetQuality( 98 );

Initializing GDI+

Do not forget to initialize and de-initialize GDI+. I'm using a helper class for that: CGDIpInitializer. It's use is self-explaining.

 // extension declaration
class CMyExtension : public CHttpServer
    CGDIpInitializer m_GDIpInitializer;
BOOL CMyExtension::GetExtensionVersion(HSE_VERSION_INFO* pVer)

    // Initialize GDI+
BOOL CMyExtension::TerminateExtension(DWORD dwFlags)
    // Shutting down GDI+

What not to do...

  • When writing an image, do not write any text... So forget about StartContent, EndContent ,WriteClient, etc...

Demo project

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:


  1. MSDN Sample: PINBALL
  2. What an ISPAPI extension is? by Mehdi Mousavi

Update history

  • 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)
    • -->


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Jonathan de Halleux
United States United States
Jonathan de Halleux is Civil Engineer in Applied Mathematics. He finished his PhD in 2004 in the rainy country of Belgium. After 2 years in the Common Language Runtime (i.e. .net), he is now working at Microsoft Research on Pex (

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
manoj kumar choubey18-Feb-12 1:05
membermanoj kumar choubey18-Feb-12 1:05 
QuestionWhat is this? "" Pin
RedDK10-Aug-09 13:26
memberRedDK10-Aug-09 13:26 
GeneralNeed Help!!! Pin
c_srishti19-Jun-04 14:06
memberc_srishti19-Jun-04 14:06 
GeneralWith GDI+... Pin
Paul Selormey2-Oct-02 3:00
memberPaul Selormey2-Oct-02 3:00 
GeneralThks Pin
Jonathan de Halleux2-Oct-02 3:44
memberJonathan de Halleux2-Oct-02 3:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180111.1 | Last Updated 4 Oct 2002
Article Copyright 2002 by Jonathan de Halleux
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid