您的位置:逆风者 VC++ 正文
 添加时间:2007-09-01 原文发表:2007-08-31 人气:62 来源:vckbase.com

本文章共1913字,分2页,当前第1页,快速翻页:
 

带光圈文字输出的实现

作者:李昊

下载源代码
逆风者

  你可能会认为生成一个带柔和阴影的特效文字与生成一个带光圈的特效文字是完全不同的,其实他们所用到的技术是完全相同的,只是在设置上有些许变化。 在带柔和阴影的效果中,我用到了GDI 中的一些插值模式来生成模糊的文字轮廓,当位图绘制平面放大时,插值模式决定原来某点像素应该怎样和周围的融合。 低质量的插值只是简单的把一个像素变换成同色色块,高质量插值如高质量双线性插值与高质量双三次插值会考虑像素色的平滑与反走样,我发现高质量双线 性插值模式最好。
  这个技术把文字绘制两次,一次在一个小位图上绘制光圈,它将被用你所选的插值模式放大,另一次将在平面上绘制实际文字。用于生成光圈的位图必须与实际 文字成比例,在这儿我用1/5,因此光圈文字大小是实际文字的1/5。

步骤如下:

  1. 建一个比实际绘制区域小的成比例的位图,这儿我用1/5;
  2. 建一个路径,把你想要生成效果的文字加入路径中;
  3. 用1中位图创建Graphics,建一个能缩小输出图形的矩阵;
  4. 用你想要的光圈颜色,填充文本路径,为了调节,用很细的画笔描出路径;
  5. 设置你要输出位图的Graphics的插值模式为高质双线形性,把光圈位图按比例放大到目标Graphic上;
  6. 最后,在目标Graphic上,按实际尺寸填充文本路径,这样将生成下面所示光圈效果;

二、代码说明请使用


 void CTextHaloEffectView::OnDraw(CDC* pDC)

{

	CTextHaloEffectDoc* pDoc = GetDocument();

	ASSERT_VALID(pDoc);

	if (!pDoc)

		return;

	//客户区大小

	CRect ClientRect;

	GetClientRect(&ClientRect);

	CSize ClientSize(ClientRect.Width(),ClientRect.Height());

	using namespace Gdiplus;

	Graphics g(pDC->m_hDC);

	RectF ClientRectangle(ClientRect.top,ClientRect.left,ClientRect.Width(),ClientRect.Height()); 

	g.FillRectangle(&SolidBrush(Color::Black),ClientRectangle);

	Bitmap bm(ClientSize.cx/5,ClientSize.cy/5,&g);



	//创建文字路径  



	GraphicsPath pth;



	//Add the string in the chosen style.  

    int style = FontStyleRegular;

	pth.AddString(L"文字光圈",-1,&FontFamily(L"宋体"),style,100,Point(20,20),NULL);



	//位图Graphics



	Graphics* bmpg = Graphics::FromImage(&bm);



	//Create a matrix that shrinks the drawing output by the fixed ratio.  



	Matrix mx(1.0f/5,0,0,1.0f/5,-(1.0f/5),-(1.0f/5));



	//Choose an appropriate smoothing mode for the halo.  



	bmpg->SetSmoothingMode(SmoothingModeAntiAlias);



	//Transform the graphics object so that the same half may be used for both halo and text output. 

	 

    //变换为位图的1/5,放大后将和实际文本相仿

	bmpg->SetTransform(&mx);



	//Using a suitable pen...



	Pen p(Color::Yellow,3);



	//Draw around the outline of the path



	bmpg->DrawPath(&p,&pth);



	//and then fill in for good measure.  



	bmpg->FillPath(&SolidBrush(Color::Yellow),&pth);







	//this just shifts the effect a little bit so that the edge isn''t cut off in the demonstration 



    //移动50,50

	g.SetTransform(&Matrix(1,0,0,1,50,50));



	//setup the smoothing mode for path drawing



	g.SetSmoothingMode(SmoothingModeAntiAlias);



	//and the interpolation mode for the expansion of the halo bitmap 



	g.SetInterpolationMode(InterpolationModeHighQualityBicubic);



	//expand the halo making the edges nice and fuzzy.  



	g.DrawImage(&bm,ClientRectangle,0,0,bm.GetWidth(),bm.GetHeight(),UnitPixel);



	//Redraw the original text 



	g.FillPath(&SolidBrush(Color::Black),&pth);



	//and you''re done.  





}       
 
本文章更多内容1 - 2 - 下一页>>
相关文章

WinCE4.2 下轻松调用 Windows Media Player
C 类对象的拷贝构造函数
VC Oracle 开发入门
MFC Activex 录音机控件
VC.NET简单实现GIF动画
清理VC工程
论软件接口中几种底层通讯的实现
简单PID数字控制的VC程序实现
在非MFC程序中引用CString
介绍一个操作DHTML表格的C 对象
浅析三线程程序开发思路与实现
.NET Remoting与分布式应用开发——初识 Re
介绍一个控制并行端口的MFC类
WTL字体类
OAL点点滴滴(二)
如何获取网页中的密码和文本输入框的内容
深入 CSocket 编程之阻塞和非阻塞模式
如何获取其它进程中窗口的窗口过程
OAL点点滴滴(一)
精通VC与MATLAB联合编程<十>——综合举例二

相关评论


本文章所属分类:首页 VC++

  热门关键字: