![]() |
Multimedia »
GDI »
Device Contexts
Advanced
CWebImageDCBy Randy MoreProvides a memory based DC into which an image may be drawn using standard GDI calls. |
GDI, Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||

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).
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).
BOOL SaveAsPNG(
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).
BOOL StreamAsPNG(
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.
Fills the entire bitmap with the color specified.

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:
ww,hh,bc,dc,rr,vv,ss,sn,sc...
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
Example:
<img src="/scripts/bar.dll?Draw&30,300,FFFFFF,
0000FF,Oct,40.0,36,3,20,00FF00,26,FFFF00,30,FF000">
would result in the following:
![]()
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.
| You must Sign In to use this message board. | |||||
|
|||||
|
|||||
|
|||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 27 Aug 2000 Editor: Smitha Vijayan |
Copyright 1999 by Randy More Everything else Copyright © CodeProject, 1999-2009 Web20 | Advertise on the Code Project |