1、我想实现在一个已经有文字内容的DC上面写上几个大字,就像加一个图层一样,要实现字体本身的半透明,即不能覆盖它下面的字体。
2、我尝试过把上层的大字体做成图片的形式,使用AlphaBlend函数贴上去,但当DC的DPI值比较大时,这个函数不能成功(返回值成功,图片没有贴上去),请问如何解决?
(集思广议,对者有分)
2、我尝试过把上层的大字体做成图片的形式,使用AlphaBlend函数贴上去,但当DC的DPI值比较大时,这个函数不能成功(返回值成功,图片没有贴上去),请问如何解决?
(集思广议,对者有分)
CRect rtWnd;
CRgn* pRgn;
CFont font,* pOldFont;
GetClientRect(&rtWnd);
font.CreatePointFont(2000,"宋体");
pOldFont=dc.SelectObject(&font);
dc.BeginPath();
dc.TextOut(rtWnd.left,rtWnd.top,"ABCDEFG");
dc.EndPath();
dc.SelectObject(pOldFont);
font.DeleteObject();
pRgn=CRgn::FromHandle(::PathToRegion(dc.GetSafeHdc()));//输入文字的区域dc.SelectClipRgn(pRgn,RGN_AND);//只绘制文字区域
Color clr(100,64,128,128);
Graphics gra(dc.GetSafeHdc());
SolidBrush brh(clr);
gra.FillRectangle(&brh,(INT)rtWnd.left,(INT)rtWnd.top,(INT)rtWnd.right,(INT)rtWnd.bottom);
dc.SelectClipRgn(0);
pRgn->DeleteObject();
GDI+使用如下:
stdafx.h中:
// use GDI+
#include <gdiplus.h> // Base include
using namespace Gdiplus; // The "umbella"
#pragma comment(lib, "gdiplus.lib") // The GDI+ binaryApp.h中:
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;App.cpp的InitInstance()中:
// Initialize GDI+.
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
ExitInstance()中:
GdiplusShutdown(gdiplusToken);在OnPaint或OnDraw中使用GDI+:
CMemDC dc(pDC); // memory dc. Graphics graphics(dc.m_hDC); Font myFont(_T("Arial"), 12);
StringFormat format;
format.SetAlignment(StringAlignmentNear);
format.SetLineAlignment(StringAlignmentCenter); SolidBrush brush(Color(0,0,128)); //画刷透明度设置
RectF rectf(0,0,100,100); CString str = _T("Hello world!");
graphics.DrawString(str,str.GetLength(),&myFont,rectf,&format,&brush);