更新时间:2015-12-06 21:59:47浏览次数:1+次
下面以实现文字的两种特效为例,说明TransformPoints函数在路径变换中的具体应用。在路径对象中,可以使用AddString函数向路径中追加文本,这些文本的轮廓代表路径的轮廓。如果对组成路径轮廓进行修改,最终的结果都会反映在文本轮廓中,所以,TransformPoints函数可以通过对点信息的修改来实现文本特效。
新建工程,加入GDI+程序必备的代码,你可以在之前我写的文章去找,有介绍。下面新建一个菜单项“GDI+学习”,新建一个子菜单项“文字特效”,建立消息响应:
void C旋转字体View::OnMatrixtranslatepoints()
{
// TODO: 在此添加命令处理程序代码
Graphics graphics(this->m_hWnd);
this->RedrawWindow();
///////构造字体系列
FontFamily fontFamily(L"宋体");
//////创建路径区域
GraphicsPath path;
SolidBrush redBrush(Color::Red);
graphics.SetTextRenderingHint(TextRenderingHintClearTypeGridFit);
graphics.SetSmoothingMode(SmoothingModeAntiAlias);
//////向区域中追加文本,字体大小为80
path.AddString(L"文字特效",-1,&fontFamily,FontStyleRegular,80,Point(0,0),NULL);
//////获取路径的点信息
INT count=path.GetPointCount();
Point* dataPoints=new Point[count];
path.GetPathPoints(dataPoints,count);
///////获取路径的点类型信息
INT num=path.GetPointCount();
BYTE* pTypes=new BYTE[num];
path.GetPathTypes(pTypes,num);
////复制路径
GraphicsPath* path2=path.Clone();
//////将文本在水平方向上缩小,在垂直方向上拉伸
Matrix matrix(0.5,0.0,0.0,3.5,0.0,0.0);
//////对points数据中的每一个成员进行矩形运算
matrix.TransformPoints(dataPoints,count);
//////根据计算后的点重新构造路径
GraphicsPath newpath(dataPoints,pTypes,count);
//////填充路径
graphics.FillPath(&redBrush,&newpath);
///////第二种特效
Matrix matrix2(0.6,0.5,0.2,1.5,160,-40);
path2->GetPathPoints(dataPoints,count);
///////根据计算后的点重新构造路径
matrix2.TransformPoints(dataPoints,count);
GraphicsPath newpath2(dataPoints,pTypes,count);
graphics.FillPath(&redBrush,&newpath2);
}
代码实现:
TransformPoints(Points* pts, INT count);
TransformPoints(PointF* pts, INT count);
相关资讯