Specific device context ?
-
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.
-
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.
CreateDIBSection accepts BITMAPINFO on input, this allows you to specify the color depth. Tomasz Sowinski -- http://www.shooltz.com
-
CreateDIBSection accepts BITMAPINFO on input, this allows you to specify the color depth. Tomasz Sowinski -- http://www.shooltz.com
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
-
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
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