Print Page | Close Window

Markup rendering with alpha channel

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=23247
Printed Date: 23 December 2024 at 3:04pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Markup rendering with alpha channel
Posted By: Marc.Gregoire
Subject: Markup rendering with alpha channel
Date 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?




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net