本文整理汇总了C++中gdiplus::Bitmap::GetPaletteSize方法的典型用法代码示例。如果您正苦于以下问题:C++ Bitmap::GetPaletteSize方法的具体用法?C++ Bitmap::GetPaletteSize怎么用?C++ Bitmap::GetPaletteSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gdiplus::Bitmap
的用法示例。
在下文中一共展示了Bitmap::GetPaletteSize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MyCreateFromGdiplusBitmap
HRESULT BitmapUtil::MyCreateFromGdiplusBitmap( Gdiplus::Bitmap& bmSrc ) throw()
{
Gdiplus::PixelFormat eSrcPixelFormat = bmSrc.GetPixelFormat();
UINT nBPP = 32;
DWORD dwFlags = 0;
Gdiplus::PixelFormat eDestPixelFormat = PixelFormat32bppRGB;
if( eSrcPixelFormat&PixelFormatGDI )
{
nBPP = Gdiplus::GetPixelFormatSize( eSrcPixelFormat );
eDestPixelFormat = eSrcPixelFormat;
}
if( Gdiplus::IsAlphaPixelFormat( eSrcPixelFormat ) )
{
nBPP = 32;
dwFlags |= createAlphaChannel;
eDestPixelFormat = PixelFormat32bppARGB;
}
BOOL bSuccess = Create( bmSrc.GetWidth(), bmSrc.GetHeight(), nBPP, dwFlags );
if( !bSuccess )
{
return( E_FAIL );
}
Gdiplus::ColorPalette* pPalette = NULL;
if( Gdiplus::IsIndexedPixelFormat( eSrcPixelFormat ) )
{
UINT nPaletteSize = bmSrc.GetPaletteSize();
pPalette = static_cast< Gdiplus::ColorPalette* >( _alloca( nPaletteSize ) );
bmSrc.GetPalette( pPalette, nPaletteSize );
RGBQUAD argbPalette[256];
ATLASSERT( (pPalette->Count > 0) && (pPalette->Count <= 256) );
for( UINT iColor = 0; iColor < pPalette->Count; iColor++ )
{
Gdiplus::ARGB color = pPalette->Entries[iColor];
argbPalette[iColor].rgbRed = BYTE( color>>RED_SHIFT );
argbPalette[iColor].rgbGreen = BYTE( color>>GREEN_SHIFT );
argbPalette[iColor].rgbBlue = BYTE( color>>BLUE_SHIFT );
argbPalette[iColor].rgbReserved = 0;
}
SetColorTable( 0, pPalette->Count, argbPalette );
}
if( eDestPixelFormat == eSrcPixelFormat )
{
// The pixel formats are identical, so just memcpy the rows.
Gdiplus::BitmapData data;
Gdiplus::Rect rect( 0, 0, GetWidth(), GetHeight() );
bmSrc.LockBits( &rect, Gdiplus::ImageLockModeRead, eSrcPixelFormat, &data );
UINT nBytesPerRow = AtlAlignUp( nBPP*GetWidth(), 8 )/8;
BYTE* pbDestRow = static_cast< BYTE* >( GetBits() );
BYTE* pbSrcRow = static_cast< BYTE* >( data.Scan0 );
for( int y = 0; y < GetHeight(); y++ )
{
memcpy( pbDestRow, pbSrcRow, nBytesPerRow );
pbDestRow += GetPitch();
pbSrcRow += data.Stride;
}
bmSrc.UnlockBits( &data );
}
else
{
// Let GDI+ work its magic
Gdiplus::Bitmap bmDest( GetWidth(), GetHeight(), GetPitch(), eDestPixelFormat, static_cast< BYTE* >( GetBits() ) );
Gdiplus::Graphics gDest( &bmDest );
gDest.DrawImage( &bmSrc, 0, 0 );
}
return( S_OK );
}