Click here to Skip to main content
13,287,856 members (44,855 online)
Click here to Skip to main content
Add your own
alternative version


37 bookmarked
Posted 3 Dec 1999


, 27 Aug 2000
Rate this:
Please Sign up or sign in to vote.
Provides a memory based DC into which an image may be drawn using standard GDI calls.

Sample Image - WebImageDC.jpg


Derived from the MFC class CDC, this class provides a memory based DC into which an image may be drawn using standard GDI calls. The resulting image may then be saved as either a PNG file or written to a CMemFile for insertion into a CHttpStream (a demonstration of this is included at the bottom of this article).


BOOL Create(CSize &pImageSize);

As with many MFC classes, CWebImageDC requires a two step creation. After being instantiated, the Create method must be called once to generate the bitmap. The CSize parameter indicates the width and height of the resulting image in pixels. If you will not be drawing over the entire bitmap, you should probably then call the Erase method (see below).

    CString &pFileName,
    BOOL pInterlaced = TRUE,
    BOOL pTransparent = FALSE,
    COLORREF pTransparentColor = RGB(255,255,255));

Saves the bitmap in PNG format to the file specified in the pFileName parameter. The optional control parameters will determine whether the resulting file is interlaced, and whether it has one of its colors set to transparent (and which color that is).

    CMemFile * pMemFile,
    BOOL pInterlaced = TRUE,
    BOOL pTransparent = FALSE,
    COLORREF pTransparentColor = RGB(255,255,255));

Writes the bitmap in PNG format to the CMemFile specified in the pMemFile parameter. The buffer associated with the MemFile can then be accessed using the .Detach() method and can be sent to a CHttpStream using the .Write() method. See the source code in the Bar example below for an example of this technique.

void Erase(COLORREF pColor);

Fills the entire bitmap with the color specified.


Sample Image

The bar chart above was generated using the CWebImageDC in an ISAPI plug-in which takes a parameter list describing a single bar in a bar chart, and returns an HTTP stream which contains the raster image of the described bar in PNG format.


The plug-in is used as follows:

<img src="/scripts/bar.dll?Draw¶meters ">

where parameters have the form:


The parameters are as follows:

  • ww = width in pixels
  • hh = height in pixels
  • bc = background color in RRGGBB format (hex)
  • dc = default color
  • label = the column label
  • rr = range for the bar
  • vv = value of the bar
  • ss = number of sigmas (divisions)
  • sn,sc = comma separated list of sigmas and colors

Note: colors are in the form RRGGBB in hex from 00 to FF


<img src="/scripts/bar.dll?Draw&30,300,FFFFFF,

would result in the following:

Bar Image

A series of these can easily be used to generate a bar chart like the one shown earlier, within an ASP page.


This class uses the PNG and ZLIB libraries provided by the PNG Working Group and the HIPNG provided by Alan Algustyniak. Thanks very much for the great libraries.


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

Randy More
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

Generalstream problem Pin
GuigaRJ6-Jan-05 6:11
memberGuigaRJ6-Jan-05 6:11 
General256 colors workaround with CImage Pin
Kurt Muellner18-Dec-02 23:52
memberKurt Muellner18-Dec-02 23:52 
GeneralDoesn't work ISAPI test Pin
Markus Julian3-Dec-02 15:33
memberMarkus Julian3-Dec-02 15:33 
GeneralWorkaround for 256 color mode Pin
bushi18-Sep-00 0:58
sussbushi18-Sep-00 0:58 
Questionhow to get around build errors Pin
Gee25-Aug-00 6:02
sussGee25-Aug-00 6:02 
Generalsaving/printing gdi calls Pin
Cameron Ditty8-Aug-00 11:17
sussCameron Ditty8-Aug-00 11:17 
GeneralI can't build it. Help me Pin
Alexey28-Jul-00 8:39
sussAlexey28-Jul-00 8:39 
Generalcontact with Author Pin
bushi26-Jul-00 23:01
sussbushi26-Jul-00 23:01 
GeneralRe: contact with Author Pin
Ernesto Perales Soto28-Jul-00 7:21
sussErnesto Perales Soto28-Jul-00 7:21 
GeneralTranparency didn't work! Pin
Floriano23-Jul-00 6:27
sussFloriano23-Jul-00 6:27 
GeneralRe: Tranparency didn't work! Pin
boothr28-May-01 10:44
memberboothr28-May-01 10:44 
GeneralMissing deflate.h Pin
Paul23-Jul-00 0:24
sussPaul23-Jul-00 0:24 
General1. Problem with ISAPI ext. 2.StdAfx.h missing Pin
bushi21-Jun-00 5:19
sussbushi21-Jun-00 5:19 
GeneralRe: 1. Problem with ISAPI ext. 2.StdAfx.h missing Pin
bushi21-Jun-00 5:24
sussbushi21-Jun-00 5:24 
Generalcancel it!!! Pin
bushi21-Jun-00 8:38
sussbushi21-Jun-00 8:38 
Generallinking errors in vc6 Pin
Henry Kho13-Apr-00 23:45
sussHenry Kho13-Apr-00 23:45 
Generalassertion error fix(temporary?) Pin
john11-Apr-00 9:51
sussjohn11-Apr-00 9:51 
GeneralRe: assertion error fix(temporary?) Pin
bushi21-Jun-00 8:33
sussbushi21-Jun-00 8:33 
RKM11-Apr-00 9:02
sussRKM11-Apr-00 9:02 
Generalassertion error Pin
john11-Apr-00 8:47
sussjohn11-Apr-00 8:47 
GeneralRe: assertion error Pin
RKM11-Apr-00 8:53
sussRKM11-Apr-00 8:53 
General256 color mode Pin
Ernesto Perales Soto7-Mar-00 15:43
sussErnesto Perales Soto7-Mar-00 15:43 
GeneralRe: 256 color mode Pin
RKM11-Apr-00 8:52
sussRKM11-Apr-00 8:52 
GeneralAnswer to DEFLATE.H Pin
Aaron Manuel5-Feb-00 20:21
sussAaron Manuel5-Feb-00 20:21 
GeneralRe: Answer to DEFLATE.H Pin
Anonymous11-Jul-02 13:33
sussAnonymous11-Jul-02 13:33 
GeneralDEFLATE.H Pin
Gary Menzel26-Jan-00 19:06
sussGary Menzel26-Jan-00 19:06 

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
Web03 | 2.8.171207.1 | Last Updated 28 Aug 2000
Article Copyright 1999 by Randy More
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid