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. Specific device context ?

Specific device context ?

Scheduled Pinned Locked Moved C / C++ / MFC
4 Posts 2 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.
  • A Offline
    A Offline
    Andrew Hoole
    wrote on last edited by
    #1

    Hi I'm going round in circles and could do with some help. I have an application that draws a whole lot of information to a window via a subclass of CView. Now I need to save a copy of what is in the window in a particular format. I thought if I created a new view using a memory device context I could get the system to draw itself to this new view and then pull the required data out of memory but I can't seem to find a way to set up a memory device context with the format that I want (16bit gray scale would be ideal - i'll settle for 8bit if I have to). CreateDC wants me to specify a lot of stuff about drivers . CreateCompatibleDC gives me something according to the current system device, but trying to select a bitmap of a particular format into this fails because the two are not compatible. CreateCompatibleBitmap seems to give me a monochrome bitmap. I'm sure it is very easily done but my brain has gone fuzzy.

    T 1 Reply Last reply
    0
    • A Andrew Hoole

      Hi I'm going round in circles and could do with some help. I have an application that draws a whole lot of information to a window via a subclass of CView. Now I need to save a copy of what is in the window in a particular format. I thought if I created a new view using a memory device context I could get the system to draw itself to this new view and then pull the required data out of memory but I can't seem to find a way to set up a memory device context with the format that I want (16bit gray scale would be ideal - i'll settle for 8bit if I have to). CreateDC wants me to specify a lot of stuff about drivers . CreateCompatibleDC gives me something according to the current system device, but trying to select a bitmap of a particular format into this fails because the two are not compatible. CreateCompatibleBitmap seems to give me a monochrome bitmap. I'm sure it is very easily done but my brain has gone fuzzy.

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      CreateDIBSection accepts BITMAPINFO on input, this allows you to specify the color depth. Tomasz Sowinski -- http://www.shooltz.com

      A 1 Reply Last reply
      0
      • T Tomasz Sowinski

        CreateDIBSection accepts BITMAPINFO on input, this allows you to specify the color depth. Tomasz Sowinski -- http://www.shooltz.com

        A Offline
        A Offline
        Andrew Hoole
        wrote on last edited by
        #3

        Seems a good idea. Now I have the following.. --------------------------------------------------------------------------- CDC dcMem; dcMem.CreateCompatibleDC(NULL); // Needed otherwise handle is uninitialised // Set up all the BITMAPINFO data char pDIBHdr[sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD)]; BITMAPINFOHEADER *pBitmapInfoHdr; RGBQUAD *pRGB; pBitmapInfoHdr = (BITMAPINFOHEADER *)pDIBHdr; // Setup the header information for the device independent bitmap which // is going to be used pBitmapInfoHdr->biSize = sizeof(BITMAPINFOHEADER); pBitmapInfoHdr->biWidth = 256; pBitmapInfoHdr->biHeight = 256; pBitmapInfoHdr->biPlanes = 1; pBitmapInfoHdr->biBitCount = 8; pBitmapInfoHdr->biCompression = 0; pBitmapInfoHdr->biSizeImage = 0; pBitmapInfoHdr->biClrUsed = 0; pRGB = (RGBQUAD *)(pDIBHdr + pBitmapInfoHdr->biSize); for(int ii=0;ii<256;ii++){ pRGB[ii].rgbRed = ii; pRGB[ii].rgbGreen = ii; pRGB[ii].rgbBlue = ii; } void* pTmpMem; CreateDIBSection(dcMem.m_hDC,(BITMAPINFO *)pDIBHdr,DIB_RGB_COLORS,&pTmpMem,NULL,0); dcMem.Rectangle(CRect(0,0,100,100)); pData = (short *)pTmpMem; // Now use pData to access the actual data out of the bitmap -------------------------------------------------------------- The output I now get doesn't reflect the Rectangle draw that I performed. Should it ? Although I have created this DIB is it selected into the DC as the memory surface onto which the draw functions will be occurring. If not how does one achieve that, so that the draw functions accessed via the DC will write into this DIB. Thanks Andrew

        T 1 Reply Last reply
        0
        • A Andrew Hoole

          Seems a good idea. Now I have the following.. --------------------------------------------------------------------------- CDC dcMem; dcMem.CreateCompatibleDC(NULL); // Needed otherwise handle is uninitialised // Set up all the BITMAPINFO data char pDIBHdr[sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD)]; BITMAPINFOHEADER *pBitmapInfoHdr; RGBQUAD *pRGB; pBitmapInfoHdr = (BITMAPINFOHEADER *)pDIBHdr; // Setup the header information for the device independent bitmap which // is going to be used pBitmapInfoHdr->biSize = sizeof(BITMAPINFOHEADER); pBitmapInfoHdr->biWidth = 256; pBitmapInfoHdr->biHeight = 256; pBitmapInfoHdr->biPlanes = 1; pBitmapInfoHdr->biBitCount = 8; pBitmapInfoHdr->biCompression = 0; pBitmapInfoHdr->biSizeImage = 0; pBitmapInfoHdr->biClrUsed = 0; pRGB = (RGBQUAD *)(pDIBHdr + pBitmapInfoHdr->biSize); for(int ii=0;ii<256;ii++){ pRGB[ii].rgbRed = ii; pRGB[ii].rgbGreen = ii; pRGB[ii].rgbBlue = ii; } void* pTmpMem; CreateDIBSection(dcMem.m_hDC,(BITMAPINFO *)pDIBHdr,DIB_RGB_COLORS,&pTmpMem,NULL,0); dcMem.Rectangle(CRect(0,0,100,100)); pData = (short *)pTmpMem; // Now use pData to access the actual data out of the bitmap -------------------------------------------------------------- The output I now get doesn't reflect the Rectangle draw that I performed. Should it ? Although I have created this DIB is it selected into the DC as the memory surface onto which the draw functions will be occurring. If not how does one achieve that, so that the draw functions accessed via the DC will write into this DIB. Thanks Andrew

          T Offline
          T Offline
          Tomasz Sowinski
          wrote on last edited by
          #4

          You've forget to select your DIBSection into dcMem. The first paremeter you're passing to CreateDIBSection is used only to initialize DC palette when you pass DIB_PAL_COLORS as 3rd param. Tomasz Sowinski -- http://www.shooltz.com

          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