在支持ClearType字体属性的手机上,界面上的字体显示不清楚,字体周围有杂色。
手机整体画图使用的是DirectDraw,在画字的时候,先画了个矩形框,然后设矩形框为透明色,设字体颜色,然后调用Drawtext,下面为代码。
_pSurfText = CreateSurface(lpDD, 144 * ScreenXRatio, 36 * ScreenXRatio);
DDSetColorKey2(_pSurfText, 0xFFFFFF);
DDRectangle(_pSurfText, 0, 0, 144 * ScreenXRatio, 36 * ScreenXRatio, 0xFFFFFF, 0xFFFFFF);
DDTextOut(_pSurfText, gPushTitleFont, 0, 0, 144 * ScreenXRatio, 14 * ScreenXRatio, 0, _adi->_name, DT_LEFT | DT_VCENTER);
画矩形框:
BOOL DDRectangle(LPDIRECTDRAWSURFACE pSurf, int x, int y, int w, int h, COLORREF lineColor, COLORREF transparentColor)
{
HDC hdc;
if(pSurf == NULL) return FALSE;
if (pSurf->GetDC(&hdc) == DD_OK)
{
HPEN hp = CreatePen(PS_SOLID, 1, lineColor);
SelectObject(hdc, hp);
HBRUSH hb = CreateSolidBrush(transparentColor);
SelectObject(hdc, hb);
Rectangle(hdc, x, y, x + w, y + h);
DeleteObject(hp);
DeleteObject(hb);
pSurf->ReleaseDC(hdc);
return TRUE;
}
else
{
return FALSE;
}
}
画字体:
BOOL DDTextOut(LPDIRECTDRAWSURFACE pSurf, HFONT font, int x, int y, int dx, int dy, COLORREF color, wchar_t* text, UINT flags)
{
HDC hdc;
if(pSurf == NULL) return FALSE;
、
if (pSurf->GetDC(&hdc) == DD_OK)
{
RECT src;
src.left = x;
src.top = y;
src.right = x + dx;
src.bottom = y + dy;
SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, color);
if(font != NULL) SelectObject(hdc, font);
DrawText(hdc, text, _tcslen(text), &src, flags);
pSurf->ReleaseDC(hdc);
return TRUE;
}
else
{
return FALSE;
}
}
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!