Drawing onto a bitmap
-
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:
-
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:
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. -
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.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:
-
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:
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