JiriNovotny
asked on
Working with 32BPP DIBSection using HDC regardless of display settings
Hello,
I have a DIB section, and I want to use standard GDI functions like LineTo, BitBlt, AlphaBlend etc. to work with it. Hovewer, I don't want to be dependent on current display settings. I would like to create DC not compatible with any device, but with memory, so I can use the full power of 32BPP bitmaps, when user has for example 256 color display mode. How to do that?
VC++ 6.0 (MFC Dialog App), SP6, PSDK Feb 2003, WinXP
Thanks.
I have a DIB section, and I want to use standard GDI functions like LineTo, BitBlt, AlphaBlend etc. to work with it. Hovewer, I don't want to be dependent on current display settings. I would like to create DC not compatible with any device, but with memory, so I can use the full power of 32BPP bitmaps, when user has for example 256 color display mode. How to do that?
VC++ 6.0 (MFC Dialog App), SP6, PSDK Feb 2003, WinXP
Thanks.
Do you have a surce code to work on?
ASKER
Sure, here is the DIB section creation:
BITMAPINFO m_tBI;
HDC m_hDC;
HBITMAP m_hDIB;
DWORD *m_pData;
HBITMAP m_hOldBmp;
......
// Create device context
m_hDC = CreateCompatibleDC(NULL);
if(m_hDC != NULL)
{
// Init struct
ZeroMemory(&m_tBI, sizeof(m_tBI));
m_tBI.bmiHeader.biSize = sizeof(m_tBI.bmiHeader);
m_tBI.bmiHeader.biPlanes = 1;
m_tBI.bmiHeader.biBitCount = 32;
m_tBI.bmiHeader.biCompress ion = BI_RGB;
m_tBI.bmiHeader.biWidth = dwWidth;
m_tBI.bmiHeader.biHeight = dwHeight;
m_tBI.bmiHeader.biSizeImag e = dwWidth * dwHeight * 4;
// Create DIB section
m_hDIB = CreateDIBSection(m_hDC, &m_tBI, DIB_RGB_COLORS, (LPVOID*)&m_pData, 0, 0);
if(m_hDIB != NULL)
{
// Select DIB into device context
m_hOldBmp = (HBITMAP)SelectObject(m_hD C, m_hDIB);
// Guarantee that GDI has completed any drawing to a bitmap
GdiFlush();
// Save sizes
m_dwWidth = dwWidth;
m_dwHeight = dwHeight;
// Validate image
m_bValid = TRUE;
// Return success
return TRUE;
}
// Error, so clean up
DeleteDC(m_hDC);
}
As you can see, I'm using current display DC. Hovewer, I want to not use such a DC, but 'memory' DC. I'm sure you understand.
BITMAPINFO m_tBI;
HDC m_hDC;
HBITMAP m_hDIB;
DWORD *m_pData;
HBITMAP m_hOldBmp;
......
// Create device context
m_hDC = CreateCompatibleDC(NULL);
if(m_hDC != NULL)
{
// Init struct
ZeroMemory(&m_tBI, sizeof(m_tBI));
m_tBI.bmiHeader.biSize = sizeof(m_tBI.bmiHeader);
m_tBI.bmiHeader.biPlanes = 1;
m_tBI.bmiHeader.biBitCount
m_tBI.bmiHeader.biCompress
m_tBI.bmiHeader.biWidth = dwWidth;
m_tBI.bmiHeader.biHeight = dwHeight;
m_tBI.bmiHeader.biSizeImag
// Create DIB section
m_hDIB = CreateDIBSection(m_hDC, &m_tBI, DIB_RGB_COLORS, (LPVOID*)&m_pData, 0, 0);
if(m_hDIB != NULL)
{
// Select DIB into device context
m_hOldBmp = (HBITMAP)SelectObject(m_hD
// Guarantee that GDI has completed any drawing to a bitmap
GdiFlush();
// Save sizes
m_dwWidth = dwWidth;
m_dwHeight = dwHeight;
// Validate image
m_bValid = TRUE;
// Return success
return TRUE;
}
// Error, so clean up
DeleteDC(m_hDC);
}
As you can see, I'm using current display DC. Hovewer, I want to not use such a DC, but 'memory' DC. I'm sure you understand.
ASKER
Is it really so hard that nobody knows?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.