void CDib::Create(int nWidth, int nHeight, int nBPP, DWORD dwFlags )
{
	CImage::Create(nWidth, nHeight, nBPP, dwFlags );
	if( IsIndexed() )
	{
		CreateDefaultPalette();
	//	GetPalette(m_palette);
	}

}
void CDib::CreateCompatibleDIB( CDC& dc, int width, int height )
{
	Empty();
	CreateDib( CSize (width,height), dc.GetDeviceCaps( BITSPIXEL ) );
	if( IsIndexed() )
	{
		if( dc.GetCurrentPalette() )
			SetPalette( *(dc.GetCurrentPalette()) );
		else CreateDefaultPalette();
	}
	
}
Exemplo n.º 3
0
bool wxGLCanvas::SetupPalette(const wxPalette& palette)
{
    const int pixelFormat = ::GetPixelFormat(m_hDC);
    if ( !pixelFormat )
    {
        wxLogLastError(_T("GetPixelFormat"));
        return false;
    }

    PIXELFORMATDESCRIPTOR pfd;
    if ( !::DescribePixelFormat(m_hDC, pixelFormat, sizeof(pfd), &pfd) )
    {
        wxLogLastError(_T("DescribePixelFormat"));
        return false;
    }

    if ( !(pfd.dwFlags & PFD_NEED_PALETTE) )
        return true;

    m_palette = palette;

    if ( !m_palette.Ok() )
    {
        m_palette = CreateDefaultPalette();
        if ( !m_palette.Ok() )
            return false;
    }

    if ( !::SelectPalette(m_hDC, GetHpaletteOf(m_palette), FALSE) )
    {
        wxLogLastError(_T("SelectPalette"));
        return false;
    }

    if ( ::RealizePalette(m_hDC) == GDI_ERROR )
    {
        wxLogLastError(_T("RealizePalette"));
        return false;
    }

    return true;
}