调色板函数CreatePalette的参数怎么设置? palVersion是系统版本信息用GetVersionEx可以得到 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 请到http://www.etechbase.net/advsearch.php,将你这个问题输入到检索框,然后选择准确匹配查询,应该可以帮助你解决这个问题的。http://www.etechbase.net/tech.php也许能够帮助你。 这有一个例子,应用到了LOGPALETTE。HOWTO: How To Use LoadImage() to Read a BMP File --------------------------------------------------------------------------------The information in this article applies to:Microsoft Win32 Application Programming Interface (API), used with:Microsoft Windows NT 4.0 Microsoft Windows 95Microsoft Windows 2000--------------------------------------------------------------------------------SUMMARYThe LoadImage API can be used to load a bitmap from a BMP file. However, it does not return palette information. This article provides sample code and describes how to retrieve the palette information for the bitmap with LoadImage. MORE INFORMATIONThe following code uses the LoadImage API to load the bitmap as a DIBSection, and then creates a palette from the DIBSection's color table. If no color table is present, a halftone palette is used: BOOL LoadBitmapFromBMPFile( LPTSTR szFileName, HBITMAP *phBitmap, HPALETTE *phPalette ) { BITMAP bm; *phBitmap = NULL; *phPalette = NULL; // Use LoadImage() to get the image loaded into a DIBSection *phBitmap = (HBITMAP)LoadImage( NULL, szFileName, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE ); if( *phBitmap == NULL ) return FALSE; // Get the color depth of the DIBSection GetObject(*phBitmap, sizeof(BITMAP), &bm ); // If the DIBSection is 256 color or less, it has a color table if( ( bm.bmBitsPixel * bm.bmPlanes ) <= 8 ) { HDC hMemDC; HBITMAP hOldBitmap; RGBQUAD rgb[256]; LPLOGPALETTE pLogPal; WORD i; // Create a memory DC and select the DIBSection into it hMemDC = CreateCompatibleDC( NULL ); hOldBitmap = (HBITMAP)SelectObject( hMemDC, *phBitmap ); // Get the DIBSection's color table GetDIBColorTable( hMemDC, 0, 256, rgb ); // Create a palette from the color tabl pLogPal = (LOGPALETTE *)malloc( sizeof(LOGPALETTE) + (256*sizeof(PALETTEENTRY)) ); pLogPal->palVersion = 0x300; pLogPal->palNumEntries = 256; for(i=0;i<256;i++) { pLogPal->palPalEntry[i].peRed = rgb[i].rgbRed; pLogPal->palPalEntry[i].peGreen = rgb[i].rgbGreen; pLogPal->palPalEntry[i].peBlue = rgb[i].rgbBlue; pLogPal->palPalEntry[i].peFlags = 0; } *phPalette = CreatePalette( pLogPal ); // Clean up free( pLogPal ); SelectObject( hMemDC, hOldBitmap ); DeleteDC( hMemDC ); } else // It has no color table, so use a halftone palette { HDC hRefDC; hRefDC = GetDC( NULL ); *phPalette = CreateHalftonePalette( hRefDC ); ReleaseDC( NULL, hRefDC ); } return TRUE; } The following code demonstrates how to use the LoadBitmapFromBMPFile function: case WM_PAINT: { PAINTSTRUCT ps; HBITMAP hBitmap, hOldBitmap; HPALETTE hPalette, hOldPalette; HDC hDC, hMemDC; BITMAP bm; hDC = BeginPaint( hWnd, &ps ); if( LoadBitmapFromBMPFile( szFileName, &hBitmap, &hPalette ) ) { GetObject( hBitmap, sizeof(BITMAP), &bm ); hMemDC = CreateCompatibleDC( hDC ); hOldBitmap = (HBITMAP)SelectObject( hMemDC, hBitmap ); hOldPalette = SelectPalette( hDC, hPalette, FALSE ); RealizePalette( hDC ); BitBlt( hDC, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY ); SelectObject( hMemDC, hOldBitmap ); DeleteObject( hBitmap ); SelectPalette( hDC, hOldPalette, FALSE ); DeleteObject( hPalette ); } EndPaint( hWnd, &ps ); } break; Additional query words: 4.00 kbdsd BITMAP DDB DIB BMP file LoadImage LoadBitmap Keywords : kbcode kbNTOS400 kbWinOS2000 kbWinOS95 kbSDKWin16 kbGDIFAQ Version : WINDOWS:; winnt:4.0 Platform : WINDOWS winnt Issue type : kbhowto Technology : Last Reviewed: December 15, 1999© 2000 Microsoft Corporation. All rights reserved. Terms of Use. --------------------------------------------------------------------------------Send feedback to MSDN.Look here for MSDN Online resources. 总非技术分有什么用? 关于多次调用dll(dll中有全局变量)的问题。有星星的进啊 问一个幼稚问题 哎呀,这个问题好棘手,折磨小弟好多天了,请各位高手快来帮帮小弟呀,小弟先谢谢了:) 如何显式调用扩展DLL中的函数? 分太多了,放! 找了半天不合适,请问如何在VC++中打开一个url,并得到返回的字串 高分求JPG的VC编程代码或DLL,要求见内容 正版的BCGControlBar Pro V19! ***********百思不得其解,高手看看,关于字符串的*************** 如何使用ftp的list命令? 一个很简单的问题!!50美金!
HOWTO: How To Use LoadImage() to Read a BMP File --------------------------------------------------------------------------------
The information in this article applies to:Microsoft Win32 Application Programming Interface (API), used with:
Microsoft Windows NT 4.0
Microsoft Windows 95
Microsoft Windows 2000--------------------------------------------------------------------------------
SUMMARY
The LoadImage API can be used to load a bitmap from a BMP file. However, it does not return palette information. This article provides sample code and describes how to retrieve the palette information for the bitmap with LoadImage. MORE INFORMATION
The following code uses the LoadImage API to load the bitmap as a DIBSection, and then creates a palette from the DIBSection's color table. If no color table is present, a halftone palette is used:
BOOL LoadBitmapFromBMPFile( LPTSTR szFileName, HBITMAP *phBitmap,
HPALETTE *phPalette )
{ BITMAP bm; *phBitmap = NULL;
*phPalette = NULL; // Use LoadImage() to get the image loaded into a DIBSection
*phBitmap = (HBITMAP)LoadImage( NULL, szFileName, IMAGE_BITMAP, 0, 0,
LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE );
if( *phBitmap == NULL )
return FALSE; // Get the color depth of the DIBSection
GetObject(*phBitmap, sizeof(BITMAP), &bm );
// If the DIBSection is 256 color or less, it has a color table
if( ( bm.bmBitsPixel * bm.bmPlanes ) <= 8 )
{
HDC hMemDC;
HBITMAP hOldBitmap;
RGBQUAD rgb[256];
LPLOGPALETTE pLogPal;
WORD i; // Create a memory DC and select the DIBSection into it
hMemDC = CreateCompatibleDC( NULL );
hOldBitmap = (HBITMAP)SelectObject( hMemDC, *phBitmap );
// Get the DIBSection's color table
GetDIBColorTable( hMemDC, 0, 256, rgb );
// Create a palette from the color tabl
pLogPal = (LOGPALETTE *)malloc( sizeof(LOGPALETTE) + (256*sizeof(PALETTEENTRY)) );
pLogPal->palVersion = 0x300;
pLogPal->palNumEntries = 256;
for(i=0;i<256;i++)
{
pLogPal->palPalEntry[i].peRed = rgb[i].rgbRed;
pLogPal->palPalEntry[i].peGreen = rgb[i].rgbGreen;
pLogPal->palPalEntry[i].peBlue = rgb[i].rgbBlue;
pLogPal->palPalEntry[i].peFlags = 0;
}
*phPalette = CreatePalette( pLogPal );
// Clean up
free( pLogPal );
SelectObject( hMemDC, hOldBitmap );
DeleteDC( hMemDC );
}
else // It has no color table, so use a halftone palette
{
HDC hRefDC; hRefDC = GetDC( NULL );
*phPalette = CreateHalftonePalette( hRefDC );
ReleaseDC( NULL, hRefDC );
}
return TRUE; }
The following code demonstrates how to use the LoadBitmapFromBMPFile function: case WM_PAINT:
{
PAINTSTRUCT ps;
HBITMAP hBitmap, hOldBitmap;
HPALETTE hPalette, hOldPalette;
HDC hDC, hMemDC;
BITMAP bm; hDC = BeginPaint( hWnd, &ps ); if( LoadBitmapFromBMPFile( szFileName, &hBitmap, &hPalette ) )
{
GetObject( hBitmap, sizeof(BITMAP), &bm );
hMemDC = CreateCompatibleDC( hDC );
hOldBitmap = (HBITMAP)SelectObject( hMemDC, hBitmap );
hOldPalette = SelectPalette( hDC, hPalette, FALSE );
RealizePalette( hDC ); BitBlt( hDC, 0, 0, bm.bmWidth, bm.bmHeight,
hMemDC, 0, 0, SRCCOPY ); SelectObject( hMemDC, hOldBitmap );
DeleteObject( hBitmap );
SelectPalette( hDC, hOldPalette, FALSE );
DeleteObject( hPalette );
}
EndPaint( hWnd, &ps ); }
break; Additional query words: 4.00 kbdsd BITMAP DDB DIB BMP file LoadImage LoadBitmap Keywords : kbcode kbNTOS400 kbWinOS2000 kbWinOS95 kbSDKWin16 kbGDIFAQ
Version : WINDOWS:; winnt:4.0
Platform : WINDOWS winnt
Issue type : kbhowto
Technology :
Last Reviewed: December 15, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.
--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.