Asked by:
Getting BITMAP structure in DirectX.

Question
-
Hi,
I have a problem, I need to get Bitmap structure(https://msdn.microsoft.com/en-us/library/windows/desktop/dd183371%28v=vs.85%29.aspx) in DirectX, when I create a bitmap thought CreateBitmapRenderTarget. Espesially I need a value: bmWidthBytes, bmBitsPixel and bmBits. Anybody can help me, in what way I can do it?
Friday, February 20, 2015 9:35 PM
All replies
-
Hi MiXenXd,
Can you explain in more detail what you are trying to do? You shouldn't need a GDI bitmap for anything in a Windows Store app. Are you trying to convert some desktop oriented sample code? There is probably a better way to achieve your goal.
--Rob
Saturday, February 21, 2015 12:51 AMModerator -
Yes, I must convert desktop oriented code. Here it is:
IDWriteBitmapRenderTarget *pRenderTarget; hResult = pGDIInterop->CreateBitmapRenderTarget( NULL, m_renderTargetWidth, m_renderTargetHeight, &pRenderTarget ); if (FAILED(hResult)) { m_lastError = L"Failed to create bitmap render target"; } else { hResult = pRenderTarget->SetPixelsPerDip(1.0f); hResult = S_OK; HDC hDC = pRenderTarget->GetMemoryDC(); if (hDC == NULL) { m_lastError = L"Failed to get render target DC"; hResult = E_FAIL; } else { HBRUSH hBrush = CreateSolidBrush(RGB(0, 0, 0)); if (hBrush == NULL) { m_lastError = L"Failed to create brush"; hResult = E_FAIL; } else { HBITMAP hBitmap = static_cast<HBITMAP>(GetCurrentObject(hDC, OBJ_BITMAP)); if (hBitmap == NULL) { m_lastError = L"GetCurrentObject failed"; hResult = E_FAIL; } else { DIBSECTION dib; int iResult = GetObject(hBitmap, sizeof(dib), &dib); if (iResult < sizeof(dib)) { m_lastError = L"GetObject failed"; hResult = E_FAIL; } else { // Store render target resources and info m_pRenderTarget = pRenderTarget; m_hDC = hDC; m_hBlackBrush = hBrush; m_bmBits = dib.dsBm.bmBits; m_bmWidthBytes = static_cast<UINT>(dib.dsBm.bmWidthBytes); m_bmBytesPixel = static_cast<UINT>(dib.dsBm.bmBitsPixel) / 8; hResult = S_OK; } } if (FAILED(hResult)) DeleteObject(hBrush); } } if (FAILED(hResult)) pRenderTarget->Release(); } pGDIInterop->Release();
I cannot use functions CreateSolidBrush, GetCurrentObject and GetObject in Windows Store app project, but I must get values of bmBits, bmWidthBytes and bmBitsPixel from BITMAP structure, that I linked previously. Is there another way to get it?
Saturday, February 21, 2015 1:48 AM -
What is this code actually trying to do in the first place? In other words, what operation are you trying to accomplish? There are much more direct ways to both render a bitmap and capture a screenshot using Direct2D or Direct3D.Saturday, February 21, 2015 7:29 AM
-
I don't want to make a screenshot. Please carefully read my first post. I repeat that I need some values of bitmap. I'm talking about this part of code:
m_bmBits = dib.dsBm.bmBits; m_bmWidthBytes = static_cast<UINT>(dib.dsBm.bmWidthBytes); m_bmBytesPixel = static_cast<UINT>(dib.dsBm.bmBitsPixel) / 8;
How can I get this values in DirectX functions?Saturday, February 21, 2015 11:40 AM -
Perhaps if you could explain what it is you are actually trying to do in your application, then we could provide more relevant advice. Your code above appears to save off a pointer to the memory that is used for a GDI render target, but that's an entirely software operation. With DirectX generally you don't have direct CPU access to the render target as a pointer.
- Edited by Chuck Walbourn - MSFTMicrosoft employee Saturday, February 21, 2015 5:58 PM
Saturday, February 21, 2015 5:58 PM -
This is a bad news for me, but maybe it is another way to replace this functions using WinRT api? I discovered, that this values is used to create a glyph pixels:
pGlyphPixels = static_cast<const char*>(m_bmBits) + rect.top * m_bmWidthBytes + rect.left * m_bmBytesPixel; RowPitch = m_bmWidthBytes; PixelStride = m_bmBytesPixel; // Glyph pixels for(UINT i=0; i < height && i < m_sheetHeight-positionY; ++i) { const UINT8 *src = static_cast<const UINT8*>(pGlyphPixels) + i*RowPitch; UINT8 *dst = m_textureData + (positionY+i)*m_sheetWidth + positionX; for(UINT j=0; j < width && j < m_sheetWidth-positionX; ++j) dst[j] = src[j*PixelStride]; }
Maybe this code give some informations about it?Monday, February 23, 2015 12:17 AM