Click here to Skip to main content
6,305,776 members and growing! (17,681 online)
Email Password   helpLost your password?
Multimedia » GDI » Device Contexts     Advanced

CWebImageDC

By Randy More

Provides a memory based DC into which an image may be drawn using standard GDI calls.
GDI, Dev
Posted:3 Dec 1999
Updated:27 Aug 2000
Views:110,864
Bookmarked:30 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
38 votes for this article.
Popularity: 6.94 Rating: 4.39 out of 5
2 votes, 40.0%
1

2

3

4
3 votes, 60.0%
5

Sample Image - WebImageDC.jpg

Introduction

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

Usage

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

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.

void Erase(COLORREF pColor);

Fills the entire bitmap with the color specified.

Sample

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.

Usage:

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:

Bar Image

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

Acknowledgements

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.

License

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


Member

Location: United States United States

Other popular GDI articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 26 (Total in Forum: 26) (Refresh)FirstPrevNext
Generalstream problem PinmemberGuigaRJ6:11 6 Jan '05  
General256 colors workaround with CImage PinmemberKurt Muellner23:52 18 Dec '02  
GeneralDoesn't work ISAPI test PinmemberMarkus Julian15:33 3 Dec '02  
GeneralWorkaround for 256 color mode Pinsussbushi0:58 18 Sep '00  
Generalhow to get around build errors PinsussGee6:02 25 Aug '00  
Generalsaving/printing gdi calls PinsussCameron Ditty11:17 8 Aug '00  
GeneralI can't build it. Help me PinsussAlexey8:39 28 Jul '00  
Generalcontact with Author Pinsussbushi23:01 26 Jul '00  
GeneralRe: contact with Author PinsussErnesto Perales Soto7:21 28 Jul '00  
GeneralTranparency didn't work! PinsussFloriano6:27 23 Jul '00  
GeneralRe: Tranparency didn't work! Pinmemberboothr10:44 28 May '01  
GeneralMissing deflate.h PinsussPaul0:24 23 Jul '00  
General1. Problem with ISAPI ext. 2.StdAfx.h missing Pinsussbushi5:19 21 Jun '00  
GeneralRe: 1. Problem with ISAPI ext. 2.StdAfx.h missing Pinsussbushi5:24 21 Jun '00  
Generalcancel it!!! Pinsussbushi8:38 21 Jun '00  
Generallinking errors in vc6 PinsussHenry Kho23:45 13 Apr '00  
Generalassertion error fix(temporary?) Pinsussjohn9:51 11 Apr '00  
GeneralRe: assertion error fix(temporary?) Pinsussbushi8:33 21 Jun '00  
GeneralFIX FOR MEMORY LEAKS! PinsussRKM9:02 11 Apr '00  
Generalassertion error Pinsussjohn8:47 11 Apr '00  
GeneralRe: assertion error PinsussRKM8:53 11 Apr '00  
General256 color mode PinsussErnesto Perales Soto15:43 7 Mar '00  
GeneralRe: 256 color mode PinsussRKM8:52 11 Apr '00  
GeneralAnswer to DEFLATE.H PinsussAaron Manuel20:21 5 Feb '00  
GeneralRe: Answer to DEFLATE.H PinsussAnonymous13:33 11 Jul '02  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin 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