C#常用GDI+文字操作汇总
作者:shichen2014 发布时间:2022-10-24 00:51:12
标签:C#,GDI+
本文实例汇总了C#常用GDI+文字操作,包含了文字的投影、倒影、旋转等常见的效果,在进行C#应用程序开发中有不错的实用价值。分享给大家供大家参考之用。具体如下:
一、投影文字
private void Form1_Paint(object sender, PaintEventArgs e)
{
//投影文字
Graphics g = this.CreateGraphics();
//设置文本输出质量
g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
g.SmoothingMode = SmoothingMode.AntiAlias;
Font newFont = new Font("Times New Roman", 48);
Matrix matrix = new Matrix();
//投射
matrix.Shear(-1.5f, 0.0f);
//缩放
matrix.Scale(1, 0.5f);
//平移
matrix.Translate(130, 88);
//对绘图平面实施坐标变换、、
g.Transform = matrix;
SolidBrush grayBrush = new SolidBrush(Color.Gray);
SolidBrush colorBrush = new SolidBrush(Color.BlueViolet);
string text = "MINGRISOFT";
//绘制阴影
g.DrawString(text, newFont, grayBrush, new PointF(0, 30));
g.ResetTransform();
//绘制前景
g.DrawString(text, newFont, colorBrush, new PointF(0, 30));
}
二、倒影文字
private void Form1_Paint(object sender, PaintEventArgs e)
{
//倒影文字
Brush backBrush = Brushes.Gray;
Brush foreBrush = Brushes.Black;
Font font = new Font("幼圆", Convert.ToInt16(40), FontStyle.Regular);
Graphics g = this.CreateGraphics();
string text = "MINGRISOFT";
SizeF size = g.MeasureString(text, font);
int posX = (this.Width - Convert.ToInt16(size.Width)) / 2;
int posY = (this.Height - Convert.ToInt16(size.Height)) / 2;
g.TranslateTransform(posX, posY);
int ascent = font.FontFamily.GetCellAscent(font.Style);
int spacing = font.FontFamily.GetLineSpacing(font.Style);
int lineHeight = System.Convert.ToInt16(font.GetHeight(g));
int height = lineHeight * ascent / spacing;
GraphicsState state = g.Save();
g.ScaleTransform(1, -1.0F);
g.DrawString(text, font, backBrush, 0, -height);
g.Restore(state);
g.DrawString(text, font, foreBrush, 0, -height);
}
三、文字填充线条
private void Form1_Paint(object sender, PaintEventArgs e)
{
//使用图像填充文字线条
TextureBrush brush = new TextureBrush(Image.FromFile(Application.StartupPath + "\\花.jpg"));
Graphics g = e.Graphics;
g.DrawString("MINGRISOFT", new Font("隶书", 60), brush, new PointF(0, 0));
}
四、旋转文字
private void Form1_Paint(object sender, PaintEventArgs e)
{
//旋转显示文字
Graphics g = e.Graphics;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
for (int i = 0; i <= 360; i += 10)
{
//平移Graphics对象到窗体中心
g.TranslateTransform(this.Width / 2, this.Height / 2);
//设置Graphics对象的输出角度
g.RotateTransform(i);
//设置文字填充颜色
Brush brush = Brushes.DarkViolet;
//旋转显示文字
g.DrawString("......MINGRISOFT", new Font("Lucida Console", 11f), brush, 0, 0);
//恢复全局变换矩阵
g.ResetTransform();
}
}
五、印版文字
private void Form1_Paint(object sender, PaintEventArgs e)
{
//印版文字
int i = 0;
Brush backBrush = Brushes.Black;
Brush foreBrush = Brushes.Violet;
Font font = new Font("Times New Roman", System.Convert.ToInt16(40), FontStyle.Regular);
Graphics g = this.CreateGraphics();
g.Clear(Color.White);
string text = "MINGRISOFT";
SizeF size = g.MeasureString(text, font);
Single posX = (this.Width - Convert.ToInt16(size.Width)) / 2;
Single posY = (this.Height - Convert.ToInt16(size.Height)) / 3;
while (i < Convert.ToInt16(20))
{
g.DrawString(text, font, backBrush, posX - i, posY + i);
i = i + 1;
}
g.DrawString(text, font, foreBrush, posX, posY);
}
相信本文所述实例对大家的C#程序设计有一定的帮助。


猜你喜欢
- 一、背景上一篇通过Java自带的JConsole来获取zookeeper状态。主要有几个不方便的地方,zk集群一般会部署3或者5台,在多个J
- FeignClient脱离eureka自定义URL需求Spring Cloud环境中的FeignClient有时候需要调用特定主机的接口,但
- 1.需求背景需要实现一个动态加载但不显示出来的视图,且该视图上有个动态生成的二维码,最后用其去生成一张快照(也就是图片)。(常见这种情况是来
- 最近刚完成一个简单的网络爬虫,开始的时候很迷茫,不知道如何入手,后来发现了很多的资料,不过真正能达到我需要,有用的资料--代码很难找。所以我
- 结构型设计模式创建型设计模式主要是为了解决创建对象的问题,而结构型设计模式则是为了解决已有对象的使用问题。适配器模式适配器模式比较好理解,因
- 系统自带的VideoView有些视频格式不支持,那么我们可以用第三方实现的VideoView替代系统的来播放视频,比较流行的有ijkplay
- 什么是ByteBuddyByteBuddy是一个java的运行时代码生成库,他可以帮助你以字节码的方式动态修改java类的代码。为什么需要B
- Parallel类是对线程的抽象,提供数据与任务的并行性。类定义了静态方法For和ForEach,使用多个任务来完成多个作业。Paralle
- 一、问题Spring2.1.5集成activiti7.1.24时访问要输入用户名和密码。 @Autowired private
- 具体代码如下所示:public class Parent { public static int a = parentStati
- startJVM是加载jvm用的方法。在JPype,apache mod等等很多地方都用到。但凡要用其他语言来加载jvm进程,就要用到这个。
- 本文实例为大家分享了Android表格布局TableLayout的具体代码,供大家参考,具体内容如下1.TableLayout TableL
- 你知道String、StringBuilder、Stringbuffer的区别吗?当你创建字符串的时候,有考虑过该使用哪个吗?别急,这篇文章
- 写在前面注:本文章使用的 SpringBoot 版本为 2.2.4.RELEASE,其 Spring 版本为 5.2.3.RELEASE前言
- 前言:时间过得真是快,现在已经是2022年了。作为开发来说,时间处理是非常繁琐的。从Java 8开始有了Java 8 T
- 使用工具:IDEA2022Tomcat9.0.41.下载Tomcat:官网:https://tomcat.apache.org/找到需要的版
- 本文实例为大家分享Winform版计算器的具体实现方法,供大家参考,具体内容如下前台页面设计后台代码实现using System;using
- 方法一:1.在pom.xml文件下添加依赖包<dependency><groupId>com.alibaba<
- 之前文章介绍过了Fluent基本框架等,其中有几个重要的方法用到了IQuery和IUpdate对象。 这2个对象是FluentMybatis
- 目录了解程序集如何在C#.NET中加载程序集,模块和引用.NET中的程序集绑定绑定重定向当问题开始发生时故障排除边注References了解