这个例子到处都是,但是没有指出是有编译错误的吗?: error C2660: 'GetDC' : function does not take 1 parameters
HDC hDC;
// We need a device context to get the DIB from
hDC = GetDC(NULL);: error C2660: 'ReleaseDC' : function does not take 2 parameters
if (!hDIB){
SelectPalette(hDC,hPal,FALSE);
ReleaseDC(NULL,hDC);
return NULL;
}
: error C2660: 'ReleaseDC' : function does not take 2 parameters
ReleaseDC(NULL,hDC);
: error C2660: 'ReleaseDC' : function does not take 2 parameters
相同
: error C2660: 'ReleaseDC' : function does not take 2 parameters
相同把DDB转换成DIB
设备相关位图(DDB)显示方式是尽可能与显示设备驱动程序相匹配,这样,DDB不可能与其他显示设备兼容;而设备无关位图(DIB)能与所有显示设备兼容,但是,其缺点在于显示速度比较慢。我们需要把DDB转换为DIB的一种情况是,需要将位图保存到一个文件中。下面是其实现的代码。
HANDLE CCaptureIEDlg::DDBToDIB(CBitmap &bitmap, DWORD dwCompression, CPalette *pPal)
{ BITMAP bm;
BITMAPINFOHEADER bi;
LPBITMAPINFOHEADER lpbi;
DWORD dwLen;
HANDLE hDIB;
HANDLE handle;
HDC hDC;
HPALETTE hPal; ASSERT( bitmap.GetSafeHandle() ); // The function has no arg for bitfields
if( dwCompression == BI_BITFIELDS )
return NULL; // If a palette has not been supplied use defaul palette
hPal=NULL;
if(pPal!=NULL)
{
hPal = (HPALETTE) pPal->GetSafeHandle();
}
if (hPal==NULL)
hPal = (HPALETTE) GetStockObject(DEFAULT_PALETTE); // Get bitmap information
bitmap.GetObject(sizeof(bm),(LPSTR)&bm); // Initialize the bitmapinfoheader
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = bm.bmWidth;
bi.biHeight = bm.bmHeight;
bi.biPlanes = 1;
bi.biBitCount = bm.bmPlanes * bm.bmBitsPixel;
bi.biCompression = dwCompression;
bi.biSizeImage = 0;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0; // Compute the size of the infoheader and the color table
int nColors = (1 << bi.biBitCount); if( nColors > 256 )
nColors = 0;
dwLen = bi.biSize + nColors * sizeof(RGBQUAD); // We need a device context to get the DIB from
hDC = GetDC(NULL);
hPal = SelectPalette(hDC,hPal,FALSE);
RealizePalette(hDC); // Allocate enough memory to hold bitmapinfoheader and color table
hDIB = GlobalAlloc(GMEM_FIXED,dwLen); if (!hDIB){
SelectPalette(hDC,hPal,FALSE);
ReleaseDC(NULL,hDC);
return NULL;
} lpbi = (LPBITMAPINFOHEADER)hDIB; *lpbi = bi; // Call GetDIBits with a NULL lpBits param, so the device driver
// will calculate the biSizeImage field
GetDIBits(hDC, (HBITMAP)bitmap.GetSafeHandle(), 0L, (DWORD)bi.biHeight,
(LPBYTE)NULL, (LPBITMAPINFO)lpbi, (DWORD)DIB_RGB_COLORS); bi = *lpbi; // If the driver did not fill in the biSizeImage field, then compute it
// Each scan line of the image is aligned on a DWORD (32bit) boundary
if (bi.biSizeImage == 0){
bi.biSizeImage = ((((bi.biWidth * bi.biBitCount) + 31) & ~31) / 8)
* bi.biHeight; // If a compression scheme is used the result may infact be larger
// Increase the size to account for this.
if (dwCompression != BI_RGB)
bi.biSizeImage = (bi.biSizeImage * 3) / 2;
} // Realloc the buffer so that it can hold all the bits
dwLen += bi.biSizeImage;
if (handle = GlobalReAlloc(hDIB, dwLen, GMEM_MOVEABLE))
hDIB = handle;
else{
GlobalFree(hDIB); // Reselect the original palette
SelectPalette(hDC,hPal,FALSE);
ReleaseDC(NULL,hDC);
return NULL;
} // Get the bitmap bits
lpbi = (LPBITMAPINFOHEADER)hDIB; // FINALLY get the DIB
BOOL bGotBits = GetDIBits( hDC, (HBITMAP)bitmap.GetSafeHandle(),
0L, // Start scan line
(DWORD)bi.biHeight, // # of scan lines
(LPBYTE)lpbi // address for bitmap bits
+ (bi.biSize + nColors * sizeof(RGBQUAD)),
(LPBITMAPINFO)lpbi, // address of bitmapinfo
(DWORD)DIB_RGB_COLORS); // Use RGB for color table if( !bGotBits )
{
GlobalFree(hDIB);
SelectPalette(hDC,hPal,FALSE);
ReleaseDC(NULL,hDC);
return NULL;
} SelectPalette(hDC,hPal,FALSE);
ReleaseDC(NULL,hDC);
return hDIB;
}怎样修改那些errors?谢谢!
HDC hDC;
// We need a device context to get the DIB from
hDC = GetDC(NULL);: error C2660: 'ReleaseDC' : function does not take 2 parameters
if (!hDIB){
SelectPalette(hDC,hPal,FALSE);
ReleaseDC(NULL,hDC);
return NULL;
}
: error C2660: 'ReleaseDC' : function does not take 2 parameters
ReleaseDC(NULL,hDC);
: error C2660: 'ReleaseDC' : function does not take 2 parameters
相同
: error C2660: 'ReleaseDC' : function does not take 2 parameters
相同把DDB转换成DIB
设备相关位图(DDB)显示方式是尽可能与显示设备驱动程序相匹配,这样,DDB不可能与其他显示设备兼容;而设备无关位图(DIB)能与所有显示设备兼容,但是,其缺点在于显示速度比较慢。我们需要把DDB转换为DIB的一种情况是,需要将位图保存到一个文件中。下面是其实现的代码。
HANDLE CCaptureIEDlg::DDBToDIB(CBitmap &bitmap, DWORD dwCompression, CPalette *pPal)
{ BITMAP bm;
BITMAPINFOHEADER bi;
LPBITMAPINFOHEADER lpbi;
DWORD dwLen;
HANDLE hDIB;
HANDLE handle;
HDC hDC;
HPALETTE hPal; ASSERT( bitmap.GetSafeHandle() ); // The function has no arg for bitfields
if( dwCompression == BI_BITFIELDS )
return NULL; // If a palette has not been supplied use defaul palette
hPal=NULL;
if(pPal!=NULL)
{
hPal = (HPALETTE) pPal->GetSafeHandle();
}
if (hPal==NULL)
hPal = (HPALETTE) GetStockObject(DEFAULT_PALETTE); // Get bitmap information
bitmap.GetObject(sizeof(bm),(LPSTR)&bm); // Initialize the bitmapinfoheader
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = bm.bmWidth;
bi.biHeight = bm.bmHeight;
bi.biPlanes = 1;
bi.biBitCount = bm.bmPlanes * bm.bmBitsPixel;
bi.biCompression = dwCompression;
bi.biSizeImage = 0;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0; // Compute the size of the infoheader and the color table
int nColors = (1 << bi.biBitCount); if( nColors > 256 )
nColors = 0;
dwLen = bi.biSize + nColors * sizeof(RGBQUAD); // We need a device context to get the DIB from
hDC = GetDC(NULL);
hPal = SelectPalette(hDC,hPal,FALSE);
RealizePalette(hDC); // Allocate enough memory to hold bitmapinfoheader and color table
hDIB = GlobalAlloc(GMEM_FIXED,dwLen); if (!hDIB){
SelectPalette(hDC,hPal,FALSE);
ReleaseDC(NULL,hDC);
return NULL;
} lpbi = (LPBITMAPINFOHEADER)hDIB; *lpbi = bi; // Call GetDIBits with a NULL lpBits param, so the device driver
// will calculate the biSizeImage field
GetDIBits(hDC, (HBITMAP)bitmap.GetSafeHandle(), 0L, (DWORD)bi.biHeight,
(LPBYTE)NULL, (LPBITMAPINFO)lpbi, (DWORD)DIB_RGB_COLORS); bi = *lpbi; // If the driver did not fill in the biSizeImage field, then compute it
// Each scan line of the image is aligned on a DWORD (32bit) boundary
if (bi.biSizeImage == 0){
bi.biSizeImage = ((((bi.biWidth * bi.biBitCount) + 31) & ~31) / 8)
* bi.biHeight; // If a compression scheme is used the result may infact be larger
// Increase the size to account for this.
if (dwCompression != BI_RGB)
bi.biSizeImage = (bi.biSizeImage * 3) / 2;
} // Realloc the buffer so that it can hold all the bits
dwLen += bi.biSizeImage;
if (handle = GlobalReAlloc(hDIB, dwLen, GMEM_MOVEABLE))
hDIB = handle;
else{
GlobalFree(hDIB); // Reselect the original palette
SelectPalette(hDC,hPal,FALSE);
ReleaseDC(NULL,hDC);
return NULL;
} // Get the bitmap bits
lpbi = (LPBITMAPINFOHEADER)hDIB; // FINALLY get the DIB
BOOL bGotBits = GetDIBits( hDC, (HBITMAP)bitmap.GetSafeHandle(),
0L, // Start scan line
(DWORD)bi.biHeight, // # of scan lines
(LPBYTE)lpbi // address for bitmap bits
+ (bi.biSize + nColors * sizeof(RGBQUAD)),
(LPBITMAPINFO)lpbi, // address of bitmapinfo
(DWORD)DIB_RGB_COLORS); // Use RGB for color table if( !bGotBits )
{
GlobalFree(hDIB);
SelectPalette(hDC,hPal,FALSE);
ReleaseDC(NULL,hDC);
return NULL;
} SelectPalette(hDC,hPal,FALSE);
ReleaseDC(NULL,hDC);
return hDIB;
}怎样修改那些errors?谢谢!
解决方案 »
- LoadImage调用出错
- call stack unavailable while child is running 错误是什么原因
- 在使用ReceiveFrom时,提示cannot convert parameter 4 from 'const int' to 'unsigned int &'?(在线等待)
- 求源码, 学校要求我们用(VC++)做一个类似ACDSEE的看图软件的课程设计,请各位大哥大姐帮下忙谢谢,
- Visual C++ , C++ , MFC 这几个的区别和联系是什么? :)
- 模态对话框与非模态对话框的区别是什么?
- 没什么钩不出来??
- 如何将线段变为轨迹呢?
- SPEEX编解码后噪音很大,求帮助
- 到底怎么修改PE文件啊??各位高人赶快现身吧,我只能给24分
- 在WINXP_PRO上能安装ORACLE????
- 关于智能指针的问题,多谢,在线等待
HDC hDC;
hDC = GetDC();// 不行'class CDC *' to 'struct HDC__ *'//====================================================
尝试 hDC = (HDC)GetDC();// 好像不行,可能丢失了信息。尝试 HDC *hDC2;
hDC2 = (HDC*)GetDC();
hDC = *hDC2; // 同样没有效果。
http://www.chinaithero.com/dev/vccool/bmp/9.htm
HDC hdc = pDC->m_hDC;
//.....
this->ReleaseDC(pDC);