Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Markup rendering with alpha channel
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Markup rendering with alpha channel

 Post Reply Post Reply
Author
Message
Marc.Gregoire View Drop Down
Newbie
Newbie


Joined: 17 January 2017
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote Marc.Gregoire Quote  Post ReplyReply Direct Link To This Post Topic: Markup rendering with alpha channel
    Posted: 17 January 2017 at 9:13am
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?

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.156 seconds.