c绘制艺术字的方法 1.docx
《c绘制艺术字的方法 1.docx》由会员分享,可在线阅读,更多相关《c绘制艺术字的方法 1.docx(9页珍藏版)》请在冰豆网上搜索。
c绘制艺术字的方法1
C#绘制艺术字的方法
今天,我们就利用C#来制作几款自己的艺术字,可能会对我们了解字体图像的制作原理有一些帮助.至于有没有使用价值我保持沉默.
一.投影效果
程序运行效果截图:
程序代码实现如下:
投影效果代码
privatevoidForm1_Paint(objectsender,PaintEventArgse)
{
//投影文字
Graphicsg=this.CreateGraphics();
//设置文本输出质量
g.TextRenderingHint=TextRenderingHint.ClearTypeGridFit;
g.SmoothingMode=SmoothingMode.AntiAlias;
FontnewFont=newFont("TimesNewRoman",48);
Matrixmatrix=newMatrix();
//投射
matrix.Shear(-1.5f,0.0f);
//缩放
matrix.Scale(1,0.5f);
//平移
matrix.Translate(130,88);
//对绘图平面实施坐标变换、、
g.Transform=matrix;
SolidBrushgrayBrush=newSolidBrush(Color.Gray);
SolidBrushcolorBrush=newSolidBrush(Color.BlueViolet);
stringtext="博客园";
//绘制阴影
g.DrawString(text,newFont,grayBrush,newPointF(0,30));
g.ResetTransform();
//绘制前景
g.DrawString(text,newFont,colorBrush,newPointF(0,30));
}
二.浮雕效果
浮雕文字实现
//浮雕文字
BrushbackBrush=Brushes.Black;
BrushforeBrush=Brushes.White;
Fontfont=newFont("宋体",Convert.ToInt16(40),FontStyle.Regular);
SizeFsize=g.MeasureString(text,font);
SingleposX=(this.Width-Convert.ToInt16(size.Width))/2;
SingleposY=(this.Height-Convert.ToInt16(size.Height))/2;
g.DrawString(text,font,backBrush,posX+1,posY+1);
g.DrawString(text,font,foreBrush,posX,posY);
三.印版效果
印版文字实现
//印版文字
inti=0;
BrushforeBrush=Brushes.Violet;
Fontfont=newFont("TimesNewRoman",System.Convert.ToInt16(40),FontStyle.Regular);
g.Clear(Color.White);
SingleposY=(this.Height-Convert.ToInt16(size.Height))/3;
while(i{g.DrawString(text,font,backBrush,posX-i,posY+i);i=i+1;}g.DrawString(text,font,foreBrush,posX,posY);}四.倒影效果程序运行效果截图:程序代码实现如下:倒影文字实现privatevoidForm1_Paint(objectsender,PaintEventArgse){//倒影文字BrushbackBrush=Brushes.Gray;BrushforeBrush=Brushes.Black;Fontfont=newFont("幼圆",Convert.ToInt16(40),FontStyle.Regular);Graphicsg=this.CreateGraphics();stringtext="博客园";SizeFsize=g.MeasureString(text,font);intposX=(this.Width-Convert.ToInt16(size.Width))/2;intposY=(this.Height-Convert.ToInt16(size.Height))/2;g.TranslateTransform(posX,posY);intascent=font.FontFamily.GetCellAscent(font.Style);intspacing=font.FontFamily.GetLineSpacing(font.Style);intlineHeight=System.Convert.ToInt16(font.GetHeight(g));intheight=lineHeight*ascent/spacing;GraphicsStatestate=g.Save();g.ScaleTransform(1,-1.0F);g.DrawString(text,font,backBrush,0,-height);g.Restore(state);g.DrawString(text,font,foreBrush,0,-height);}五.阴影效果程序运行效果截图:阴影文字实现privatevoidForm1_Paint(objectsender,PaintEventArgse){//阴影文字stringtext="博客园";BrushshadowBrush=Brushes.Gray;BrushforeBrush=Brushes.Black;Fontfont=newFont("幼圆",Convert.ToInt16(40),FontStyle.Regular);Graphicsg=this.CreateGraphics();SizeFsize=g.MeasureString(text,font);SingleposX=(this.Width-Convert.ToInt16(size.Width))/4;SingleposY=(this.Height-Convert.ToInt16(size.Height))/3;g.DrawString(text,font,shadowBrush,posX+Convert.ToInt16(20),posY+Convert.ToInt16(20));g.DrawString(text,font,foreBrush,posX,posY);}六.纹理效果程序运行效果截图:程序代码实现如下:线理效果实现privatevoidForm1_Paint(objectsender,PaintEventArgse){//使用图像填充文字线条TextureBrushbrush=newTextureBrush(Image.FromFile(Application.StartupPath+"\\myPicture.jpg"));Graphicsg=e.Graphics;g.DrawString("博客园",newFont("隶书",60),brush,newPointF(0,0));}七.倾斜效果程序运行效果截图:程序代码实现如下:倾斜效果实现privatevoidForm1_Paint(objectsender,PaintEventArgse){BrushforeBrush=Brushes.Blue;Fontfont=newFont("幼圆",Convert.ToInt16(40),FontStyle.Regular);Graphicsg=this.CreateGraphics();stringtext="博客园";SizeFsize=g.MeasureString(text,font);SingleposX=(this.Width-Convert.ToInt16(size.Width))/2;SingleposY=(this.Height-Convert.ToInt16(size.Height))/2;g.TranslateTransform(posX,posY);Matrixtransform=g.Transform;//右倾斜文字//floatshearX=-0.230F;//左倾斜文字floatshearX=0.550F;floatshearY=0.10F;transform.Shear(shearX,shearY);g.Transform=transform;g.DrawString(text,font,foreBrush,0,0);}八.渐变色效果程序代码实现如下:渐变色效果实现privatevoidForm1_Paint(objectsender,PaintEventArgse){//渐变色文字Stringtext="博客园";BrushShadowBrush=Brushes.Gray;BrushForeBrush=Brushes.Black;Fontfont=newFont("幼圆",System.Convert.ToInt16(40),FontStyle.Regular);Graphicsg=this.CreateGraphics();//g.Clear(Color.White);PointFpoint=newPointF(0,0);SizeFsize=g.MeasureString(text,font);RectangleFrectangle=newRectangleF(point,size);Brushbrush=newLinearGradientBrush(rectangle,Color.Red,Color.Green,LinearGradientMode.Horizontal);intwidth=(this.Width-Convert.ToInt16(size.Width))/2;intheight=(this.Height-Convert.ToInt16(size.Height))/2;g.DrawString(text,font,brush,width,height);}九.旋转效果程序运行效果截图:程序代码实现如下:旋转效果实现privatevoidForm1_Paint(objectsender,PaintEventArgse){//旋转显示文字Graphicsg=e.Graphics;g.SmoothingMode=System.Drawing.Drawing2D.SmoothingMode.AntiAlias;for(inti=0;i<=360;i+=10){//平移Graphics对象到窗体中心g.TranslateTransform(this.Width/2,this.Height/2);//设置Graphics对象的输出角度g.RotateTransform(i);//设置文字填充颜色Brushbrush=Brushes.DarkViolet;//旋转显示文字g.DrawString(".bokeyuan",newFont("LucidaConsole",11f),brush,0,0);//恢复全局变换矩阵g.ResetTransform();}}十...........后记:还有很多,原理都相当简单,绘制字体图关键要熟悉三个常用绘图类Brush,Font,Graphics;这里用到的主要方法是Graphics类的DrowString.
g.DrawString(text,font,backBrush,posX-i,posY+i);
i=i+1;
四.倒影效果
倒影文字实现
//倒影文字
BrushbackBrush=Brushes.Gray;
BrushforeBrush=Brushes.Black;
Fontfont=newFont("幼圆",Convert.ToInt16(40),FontStyle.Regular);
intposX=(this.Width-Convert.ToInt16(size.Width))/2;
intposY=(this.Height-Convert.ToInt16(size.Height))/2;
g.TranslateTransform(posX,posY);
intascent=font.FontFamily.GetCellAscent(font.Style);
intspacing=font.FontFamily.GetLineSpacing(font.Style);
intlineHeight=System.Convert.ToInt16(font.GetHeight(g));
intheight=lineHeight*ascent/spacing;
GraphicsStatestate=g.Save();
g.ScaleTransform(1,-1.0F);
g.DrawString(text,font,backBrush,0,-height);
g.Restore(state);
g.DrawString(text,font,foreBrush,0,-height);
五.阴影效果
阴影文字实现
//阴影文字
BrushshadowBrush=Brushes.Gray;
SingleposX=(this.Width-Convert.ToInt16(size.Width))/4;
g.DrawString(text,font,shadowBrush,posX+Convert.ToInt16(20),posY+Convert.ToInt16(20));
六.纹理效果
线理效果实现
//使用图像填充文字线条
TextureBrushbrush=newTextureBrush(Image.FromFile(Application.StartupPath+"\\myPicture.jpg"));
Graphicsg=e.Graphics;
g.DrawString("博客园",newFont("隶书",60),brush,newPointF(0,0));
七.倾斜效果
倾斜效果实现
BrushforeBrush=Brushes.Blue;
Matrixtransform=g.Transform;
//右倾斜文字
//floatshearX=-0.230F;
//左倾斜文字
floatshearX=0.550F;
floatshearY=0.10F;
transform.Shear(shearX,shearY);
g.Transform=transform;
g.DrawString(text,font,foreBrush,0,0);
八.渐变色效果
渐变色效果实现
//渐变色文字
Stringtext="博客园";
BrushShadowBrush=Brushes.Gray;
BrushForeBrush=Brushes.Black;
Fontfont=newFont("幼圆",System.Convert.ToInt16(40),FontStyle.Regular);
//g.Clear(Color.White);
PointFpoint=newPointF(0,0);
RectangleFrectangle=newRectangleF(point,size);
Brushbrush=newLinearGradientBrush(rectangle,Color.Red,Color.Green,LinearGradientMode.Horizontal);
intwidth=(this.Width-Convert.ToInt16(size.Width))/2;
intheight=(this.Height-Convert.ToInt16(size.Height))/2;
g.DrawString(text,font,brush,width,height);
九.旋转效果
旋转效果实现
//旋转显示文字
g.SmoothingMode=System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
for(inti=0;i<=360;i+=10)
//平移Graphics对象到窗体中心
g.TranslateTransform(this.Width/2,this.Height/2);
//设置Graphics对象的输出角度
g.RotateTransform(i);
//设置文字填充颜色
Brushbrush=Brushes.DarkViolet;
g.DrawString("
.bokeyuan",newFont("LucidaConsole",11f),brush,0,0);
//恢复全局变换矩阵
十...........
后记:
还有很多,原理都相当简单,绘制字体图关键要熟悉三个常用绘图类
Brush,Font,Graphics;这里用到的主要方法是Graphics类的DrowString.
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1