Click here to Skip to main content
6,596,602 members and growing! (21,343 online)
Email Password   helpLost your password?
Multimedia » General Graphics » General     Intermediate

CBitmapDC - An automatic memory DC wrapper

By Anneke Sicherer-Roetman

A handy class that provides a memory bitmap device context
VC6, MFC, Dev
Posted:24 Nov 1999
Views:94,629
Bookmarked:37 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
26 votes for this article.
Popularity: 6.20 Rating: 4.38 out of 5
3 votes, 21.4%
1

2
1 vote, 7.1%
3
1 vote, 7.1%
4
9 votes, 64.3%
5
  • Download demo project - 18 Kb
  • Download source - 5 Kb
  • CBitmapDC is a subclass of CDC. It is a handy little class that provides a memory bitmap device context without having to reinvent the wheel every time you need one.

    Example 1

    CBitmapDC can be used to make a CBitmap on the fly
    1. make a memory bitmap DC by calling CBitmapDC's constructor with the desired bitmap width and height
    2. draw in this device context with normal CDC drawing functions
    3. call CBitmapDC's Close function, this returns a pointer to the finished CBitmap
    4. do whatever you want to do with the CBitmap
    5. delete the CBitmap
    void CMyView::OnDraw(CDC* pDC)
    {
      CBitmapDC bitmapDC(50, 50, pDC);
      bitmapDC.Rectangle(0, 0, 50, 50);
      bitmapDC.MoveTo(0,50);
      bitmapDC.LineTo(50,0);
      CBitmap *pbmp = bitmapDC.Close();
      DrawBitmap(pbmp, pDC, CPoint(10, 10));
      delete pbmp;
    }
    

    Example 2

    CBitmapDC can be used as a temporary scratchpad
    1. make a memory bitmap DC by calling CBitmapDC's constructor with the desired bitmap width and height
    2. draw in this device context with normal CDC drawing functions
    3. do whatever you want to do e.g. blit the memory DC to screen
    4. use the automatic cleanup of CBitmapDC's destructor
    void CMyView::OnDraw(CDC* pDC)
    {
      CBitmapDC bitmapDC_2(50, 50, pDC);
      bitmapDC_2.Rectangle(0, 0, 50, 50);
      bitmapDC_2.MoveTo(0, 0);
      bitmapDC_2.LineTo(50, 50);
      pDC->BitBlt(200, 10, 50, 50, &bitmapDC_2, 0, 0, SRCCOPY);
    }
    

    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

    Anneke Sicherer-Roetman


    Member

    Occupation: Web Developer
    Location: Netherlands Netherlands

    Other popular General Graphics articles:

    • A flexible charting library for .NET
      Looking for a way to draw 2D line graphs with C#? Here's yet another charting class library with a high degree of configurability, that is also easy to use.
    • CxImage
      CxImage is a C++ class to load, save, display, transform BMP, JPEG, GIF, PNG, TIFF, MNG, ICO, PCX, TGA, WMF, WBMP, JBG, J2K images.
    • 3D Pie Chart
      A class library for drawing 3D pie charts.
    • Barcode Image Generation Library
      This library was designed to give an easy class for developers to use when they need to generate barcode images from a string of data.
    • ImageStone
      An article on a library for image manipulation.
    Article Top
    You must Sign In to use this message board.
    FAQ FAQ 
     
    Noise Tolerance  Layout  Per page   
     Msgs 1 to 15 of 15 (Total in Forum: 15) (Refresh)FirstPrevNext
    GeneralHow to display a bitmap image into a dialog in vc++/mfc PinsussAnonymous0:49 3 Apr '05  
    GeneralPrinting PinmemberGavriloaie Andrei8:25 11 Nov '04  
    Generalhow to load Bitmap after a image manipulation? Pinmembergilazilla5:47 18 Aug '04  
    Generalthanks very much Pinmemberphilipcunningham3:16 12 Apr '04  
    GeneralWindows CE PinmemberJoão Paulo Figueira3:53 11 Sep '03  
    GeneralCBITMAPDC PinmemberMaverick5:00 1 Jan '02  
    GeneralSame thing using CMemDC... PinmemberAnonymous23:14 19 Aug '01  
    GeneralHow can i do it PinsussYoo18:27 28 Sep '00  
    GeneralRe: How can i do it PinmemberAnneke Sicherer-Roetman0:52 29 Sep '00  
    GeneralRe: How can i do it - bugfix PinsussAnonymous10:25 27 May '03  
    GeneralRe: How can i do it - bugfix PinmemberAnneke Sicherer-Roetman21:57 27 May '03  
    GeneralRe: How can i do it - bugfix PinmemberBarryHolleran5:56 17 Feb '04  
    GeneralRe: How can i do it - bugfix PinmemberBarryHolleran6:01 17 Feb '04  
    GeneralRe: How can i do it - bugfix PinmemberWolfgang Kleinschmit0:21 6 Apr '04  
    GeneralRe: How can i do it PinmemberJHAKAS21:50 17 Apr '04  

    General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    PermaLink | Privacy | Terms of Use
    Last Updated: 24 Nov 1999
    Editor: Chris Maunder
    Copyright 1999 by Anneke Sicherer-Roetman
    Everything else Copyright © CodeProject, 1999-2009
    Web13 | Advertise on the Code Project