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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Drawing onto a bitmap

Drawing onto a bitmap

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsquestion
4 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.
  • S Offline
    S Offline
    softwaremonkey
    wrote on last edited by
    #1

    Hi, Does anyone have any code snippets showing what I need to do in order to draw what usually goes to a DC onto a bitmap instead? I am not being lazy, I am just into recycling :laugh:

    _ B 2 Replies Last reply
    0
    • S softwaremonkey

      Hi, Does anyone have any code snippets showing what I need to do in order to draw what usually goes to a DC onto a bitmap instead? I am not being lazy, I am just into recycling :laugh:

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      Drawing is always done to a device context. To create a bitmap out of it, the device context can be saved as a bitmap. I found one article on CP - http://www.codeproject.com/KB/graphics/drawing2bitmap.aspx

      «_Superman_»
      I love work. It gives me something to do between weekends.

      Microsoft MVP (Visual C++)

      Polymorphism in C

      S 1 Reply Last reply
      0
      • _ _Superman_

        Drawing is always done to a device context. To create a bitmap out of it, the device context can be saved as a bitmap. I found one article on CP - http://www.codeproject.com/KB/graphics/drawing2bitmap.aspx

        «_Superman_»
        I love work. It gives me something to do between weekends.

        Microsoft MVP (Visual C++)

        Polymorphism in C

        S Offline
        S Offline
        softwaremonkey
        wrote on last edited by
        #3

        Thanks Superman, that looks to be EXACTLY what I need to do. I did try searching the Code Project site first but I probably chose bad keywords. :thumbsup: :thumbsup: :cool:

        1 Reply Last reply
        0
        • S softwaremonkey

          Hi, Does anyone have any code snippets showing what I need to do in order to draw what usually goes to a DC onto a bitmap instead? I am not being lazy, I am just into recycling :laugh:

          B Offline
          B Offline
          basementman
          wrote on last edited by
          #4

          Below is a code snippet that demonstrates creating a memory DC, calling functions that use std GDI funtions to draw onto the DC, extracting the BMP from the DC and doing something with it, and finally clean up: BOOL DoChart(CallContextObj *pCallContextObj) { CDC oMemDC; CBitmap *pOldBmp; CBitmap oBmp; long lWidth = 300; long lHeight = 200; pCallContextObj->GetParameterValue(_T("ChartWidth"),&lWidth); pCallContextObj->GetParameterValue(_T("ChartHeight"),&lHeight); CRect oBmpSize(0,0,lWidth,lHeight); oMemDC.CreateCompatibleDC(NULL); int iOldMapMode = oMemDC.SetMapMode(MM_TEXT); CWindowDC dcScreen(NULL); oBmp.CreateCompatibleBitmap(&dcScreen,oBmpSize.Width(), oBmpSize.Height()); pOldBmp = oMemDC.SelectObject(&oBmp); WORD wChartType = 88; pCallContextObj->GetParameterValue(_T("ChartType"),&wChartType); BOOL bRetval = FALSE; TCHAR caError[1024]; _tcscpy(caError,_T("Invalid Chart Type")); switch (wChartType) { case 0: bRetval = DoLineChart(pCallContextObj,&oMemDC,caError,oBmpSize); break; case 1: bRetval = DoBarChart(FALSE,pCallContextObj,&oMemDC,caError,oBmpSize); break; case 2: bRetval = DoBarChart(TRUE,pCallContextObj,&oMemDC,caError,oBmpSize); break; case 3: bRetval = DoOpenHiLowCloseChart(pCallContextObj,&oMemDC,caError,oBmpSize); break; case 4: bRetval = DoPieChart(pCallContextObj,&oMemDC,caError,oBmpSize); break; } if (bRetval) { char caHeaders[1024]; #ifdef UNICODE BYTE *cpBuf = (BYTE *)pCallContextObj->GetUTF8OutputBufferPtr(); #else BYTE *cpBuf = (BYTE *)pCallContextObj->GetOutputBufferPtr(); #endif long lQuality = 75; pCallContextObj->GetParameterValue(_T("ImageQuality"),&lQuality); long lDataSize = WriteImage(oBmp,cpBuf,pCallContextObj->GetOutputBufferSize(),caError,(DWORD)lQuality); if (lDataSize > 0) { pCallContextObj->SuppressHeaders(); sprintf(caHeaders,"Content-Type: image/jpeg\r\nContent-Length: %d\r\n\r\n",lDataSize); // write out our custom headers if (pCallContextObj->ServerSupportFunction(HSE_REQ_SEND_RESPONSE_HEADER,"200 OK",0,(LPDWORD)caHeaders) || ::GetLastError() == 10054) pCallContextObj->WriteClient((LPVOID)cpBuf,(LPDWORD)&lDataSize); *cpBu

          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