Hi,
I'm trying to rendering some markup text to a bitmap but I would like to have a correct alpha channel in that bitmap. For example, take the following code:
CXTPMarkupContext* ctx = XTPMarkupCreateContext(); CXTPMarkupUIElement* pUIElement = XTPMarkupParseText(ctx, _T("<Page VerticalAlignment='Top' HorizontalAlignment='Left'>") _T("<Border BorderThickness='5' BorderBrush='#500000FF' Background='white' CornerRadius='16' Padding='8'>") _T("<TextBlock>Test</TextBlock>") _T("</Border>") _T("</Page>")); CSize desiredSize = XTPMarkupMeasureElement(pUIElement); CRect rc (CPoint(0, 0), desiredSize); pUIElement->Arrange(rc);CDC memoryDC; memoryDC.CreateCompatibleDC(nullptr); memoryDC.SetBkMode(TRANSPARENT); BITMAPINFO pbiDIB; pbiDIB.bmiHeader.biBitCount = 32; pbiDIB.bmiHeader.biClrImportant = 0; pbiDIB.bmiHeader.biClrUsed = 0; pbiDIB.bmiHeader.biCompression = BI_RGB; pbiDIB.bmiHeader.biPlanes = 1; pbiDIB.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); pbiDIB.bmiHeader.biSizeImage = 0; pbiDIB.bmiHeader.biXPelsPerMeter = 0; pbiDIB.bmiHeader.biYPelsPerMeter = 0; pbiDIB.bmiHeader.biHeight = rc.Height(); pbiDIB.bmiHeader.biWidth = rc.Width(); BYTE* pDIBitmap = nullptr; HBITMAP bmpRender = ::CreateDIBSection(memoryDC, &pbiDIB, DIB_RGB_COLORS, (void **)&pDIBitmap, 0, 0); HBITMAP oldBmp = (HBITMAP)SelectObject(memoryDC, bmpRender); XTPMarkupRenderElement(pUIElement, memoryDC.GetSafeHdc(), rc); XTPMarkupReleaseElement(pUIElement); XTPMarkupReleaseContext(ctx); ctx = nullptr; SelectObject(memoryDC, oldBmp); |
The R, G, and B channels are perfect. But, the resulting alpha channel looks as follows:
The border is nicely anti-aliased, but the alpha values for the text are quite wrong. These are completely black meaning the text would be completely transparent.
What am I doing wrong here?
|