吉吉于

C#每天抄一点(19):图片上加载文字

 

01 /*
02 * 由SharpDevelop创建。
03 * 用户: Lazynight
04 * 日期: 2011/10/20
05 * 时间: 12:37
06 *
07 * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
08 */
09 using System;
10 using System.Collections.Generic;
11 using System.Drawing;
12 using System.Windows.Forms;
13 using System.Drawing.Drawing2D;
14 namespace Lazy19_图像上加载文字
15 {
16     public partial class MainForm : Form
17     {
18         public MainForm()
19         {
20             InitializeComponent();
21
22         }
23
24         void Button1Click(object sender, EventArgs e)
25         {
26             string Lazy_name;
27             openFileDialog1.Filter=“*.jpg,*.jpeg,*.bmp,*.gif,*.ico,*.png,*.tif,*.wmf|*.jpg;*.jpeg;*.bmp;*.gif;*.ico;*.png;*.tif;*.wmf”;
28             //设置打开图像的类型
29             openFileDialog1.ShowDialog();//打开对话框
30             Lazy_name=openFileDialog1.FileName;
31             pictureBox1.Image=Image.FromFile(Lazy_name);//显示打开图像
32         }
33
34         void MainFormLoad(object sender, EventArgs e)
35         {
36
37         }
38
39         void Button2Click(object sender, EventArgs e)
40         {
41             if(textBox1.Text!=“”)
42             {
43                 Graphics Lazy_pic=pictureBox1.CreateGraphics();//创建Graphics对象实例
44                 SolidBrush Lazy_brush=new SolidBrush(Color.Black);//定义画笔类型,颜色
45                 Font Lazy_font=new Font(“微软雅黑”,20);//字体类型,颜色
46                 Lazy_pic.DrawString(textBox1.Text,Lazy_font,Lazy_brush,new Rectangle(10,10,200,120));
47                 //调用DrawString方法在图像上写文字   
48             }
49             else
50             {
51                 //提示对话框
52                 MessageBox.Show(this,“输入要加载的文字内容撒~”,“温情提示”,MessageBoxButtons.OK,MessageBoxIcon.Warning);
53             }
54         }
55
56         void Button3Click(object sender, EventArgs e)
57         {
58             if(textBox1.Text!=“”)
59             {
60                 Graphics Lazy_pic =pictureBox1.CreateGraphics();
61                 LinearGradientBrush Lazy_brush=new LinearGradientBrush(ClientRectangle,Color.Blue,Color.Red,LinearGradientMode.BackwardDiagonal);
62                 //定义渐变画笔
63                 Font Lazy_font=new Font(“微软雅黑”,20);
64                 Lazy_pic.DrawString(textBox1.Text,Lazy_font,Lazy_brush,new Rectangle(20,40,200,120));
65             }
66             else
67             {
68                 //提示对话框
69                 MessageBox.Show(this,“输入要加载的文字内容撒~”,“温情提示”,MessageBoxButtons.OK,MessageBoxIcon.Warning);
70             }
71         }
72     }
73 }

下载源码

转载请注明:于哲的博客 » C#每天抄一点(19):图片上加载文字