Reputation: 397
I'm using this code to sign a frame from webcam:
Font = CreateFont(18, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, VARIABLE_PITCH, "times");
...
HDC hDC = CreateCompatibleDC(NULL);
unsigned char * img = 0;
HBITMAP hBitmap = CreateDIBSection(hDC, &BMI, DIB_RGB_COLORS, (void**)&img, NULL, 0);
memcpy(img, CameraFrame.data, CameraFrame.size());
free(CameraFrame.data);
CameraFrame.data = img;
SelectObject(hDC, hBitmap);
SelectObject(hDC, Font);
SetBkMode(hDC, TRANSPARENT);
SetTextColor(hDC, RGB(255,255,255));
string Text = "Test";
DrawTextA(hDC, Text.c_str(), Text.size(), &rect, DT_CENTER | DT_WORDBREAK);
DeleteDC(hDC);
Of course the color scale of frames will differ, and I need the text to be visible anyway.
How to DrawText
with outline? For example, white text with black outline.
Upvotes: 2
Views: 4445
Reputation: 56
Here is what I would recommend:
Step 1 happens when initializing. Steps 2-4 happen each time you paint.
Upvotes: 0
Reputation: 48038
With GDI, you can use BeginPath, DrawText, EndPath, and then StrokeAndFillPath, as long as you're using an "outline" font (like TrueType or OpenType).
::BeginPath(ps.hdc);
RECT rc;
GetClientRect(&rc);
::DrawTextW(ps.hdc, L"Hello", 5, &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
::EndPath(ps.hdc);
::StrokeAndFillPath(ps.hdc);
The StrokeAndFillPath will use the currently selected pen for the outline and the currently selected brush to fill it in. You can use TextOut or other GDI calls inside the BeginPath/EndPath.
You won't get any anti-aliasing like you'd have with regular text output, so it won't be as crisp as your regular ClearType text. At larger sizes, this isn't a big issue.
Upvotes: 2
Reputation: 2380
Two approaches:
Draw the Text in black, but scaled slightly larger by 2 pixels (good luck) and offset by (-1,-1) then normally in white in the center.
Draw the Text in black, but offset { (-1,-1), (1,1), (-1,1), (1,-1) }
and then in white in the center.
Upvotes: 3