Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to Save the DC.

How to Save the DC.

Scheduled Pinned Locked Moved C / C++ / MFC
graphicstutorialquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GauranG Shah
    wrote on last edited by
    #1

    Hello Friends, I am using the Win32 Application. (its good to make clear).And I want to save the Device Context into any Bitmap File. I.e. I have a HDC called hdc. I just want to save it into a .bmp File.Is this possible to do.:confused: if yes please tell me How ??.

    H C 2 Replies Last reply
    0
    • G GauranG Shah

      Hello Friends, I am using the Win32 Application. (its good to make clear).And I want to save the Device Context into any Bitmap File. I.e. I have a HDC called hdc. I just want to save it into a .bmp File.Is this possible to do.:confused: if yes please tell me How ??.

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      See Saving a Drawing to a Bitmap File[^] (Its with MFC but I think you can convert to Win32).

      G 1 Reply Last reply
      0
      • G GauranG Shah

        Hello Friends, I am using the Win32 Application. (its good to make clear).And I want to save the Device Context into any Bitmap File. I.e. I have a HDC called hdc. I just want to save it into a .bmp File.Is this possible to do.:confused: if yes please tell me How ??.

        C Offline
        C Offline
        codeII
        wrote on last edited by
        #3

        #include "atlimage.h" bool SafeDcToBmp( const CDC& cdc, LPCTSTR cBitmapPathAndName ) { CImage image; CRect cdcRect; bool bSucc = false; if( cdc.GetWindow( ) ) { cdc.GetWindow( )->GetClientRect( cdcRect ); image.Create( cdcRect.Width( ), cdcRect.Height( ), 24 ); ::BitBlt( image.GetDC( ), 0,0, image.GetWidth( ), image.GetHeight( ), cdc.m_hDC, 0,0,SRCCOPY ); bSucc = ( S_OK == image.Save( cBitmapPathAndName ) ); } return bSucc; } //Usage CDC cdc; cdc.Attach( GetDC( )->m_hDC ); SafeDcToBmp( cdc, _T("c:\\MyFile.bmp") ); cdc.Detach( );

        H 1 Reply Last reply
        0
        • C codeII

          #include "atlimage.h" bool SafeDcToBmp( const CDC& cdc, LPCTSTR cBitmapPathAndName ) { CImage image; CRect cdcRect; bool bSucc = false; if( cdc.GetWindow( ) ) { cdc.GetWindow( )->GetClientRect( cdcRect ); image.Create( cdcRect.Width( ), cdcRect.Height( ), 24 ); ::BitBlt( image.GetDC( ), 0,0, image.GetWidth( ), image.GetHeight( ), cdc.m_hDC, 0,0,SRCCOPY ); bSucc = ( S_OK == image.Save( cBitmapPathAndName ) ); } return bSucc; } //Usage CDC cdc; cdc.Attach( GetDC( )->m_hDC ); SafeDcToBmp( cdc, _T("c:\\MyFile.bmp") ); cdc.Detach( );

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          Your code is good but here a problem he didnt use of MFC,his program is Win32.;)

          1 Reply Last reply
          0
          • H Hamid Taebi

            See Saving a Drawing to a Bitmap File[^] (Its with MFC but I think you can convert to Win32).

            G Offline
            G Offline
            GauranG Shah
            wrote on last edited by
            #5

            Thnx for help. But i already mention that I am Using Win32 Not MFC. So. If you have the Solution for Win32 please tell me.

            H 1 Reply Last reply
            0
            • G GauranG Shah

              Thnx for help. But i already mention that I am Using Win32 Not MFC. So. If you have the Solution for Win32 please tell me.

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #6

              Yeah I saw your question(I said that article is MFC) and that article but if you see that article you can find answer to write HDC to a bmp file I wrote

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups