如何在图像上绘制文字 [英] how to draw text on image
本文介绍了如何在图像上绘制文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试制作类似油漆的程序,我想在图像中添加文字但是当我点击按钮时图像将替换为文字。
i try to make program like paint, i want to add text to an image but the image will replace with text when i click the button.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void DrawString()
{
FontDialog fndialog = new FontDialog();
System.Drawing.Graphics formGraphics = this.CreateGraphics();
string drawString = textBox2.Text;
System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 16);
System.Drawing.SolidBrush drawBrush = new
System.Drawing.SolidBrush(System.Drawing.Color.Black);
float x = 13.300f;
float y = 1.300f;
formGraphics.DrawString(drawString, drawFont, drawBrush, x, y);
drawFont.Dispose();
drawBrush.Dispose();
formGraphics.Dispose();
}
public void DrawText()
{
//fix yang ini.
string abc = textBox1.Text;
Graphics grf = pictureBox1.CreateGraphics();
try
{
int x = Convert.ToInt32(textBox4.Text);
int y =Convert.ToInt32(textBox5.Text);
int size = Convert.ToInt32(textBox3.Text);
string font = textBox2.Text;
FontFamily fnfm = new FontFamily(font);
FontDialog fndial = new FontDialog();
grf.Clear(Color.White);
using (Font myFont = new Font(fnfm , size))
{
grf.DrawString(abc , myFont, Brushes.Green, new PointF(x, y));
}
}
finally
{
grf.Dispose();
}
}
private void button1_Click(object sender, EventArgs e)
{
DrawText();
}
}
i use以下代码。
i use the following code.
推荐答案
参见在图像上动态写入文本 [ ^ ]
和
将文本写入透明GIF [ ^ ]
和
另一个动态ASP.NET文本图像 [ ^ ]
See Dynamically Write Text On An Image[^]
and
Write text to transparent GIF[^]
and
Another Dynamic ASP.NET Text Image[^]
删除下面的l您的代码中的ine
remove below line from your code
//grf.Clear(Color.White);
你已经完成了:)
< b> 为什么!
清除方法清除图形的绘图表面并将背景颜色设置为白色,您将丢失原始图片已加载。
这篇关于如何在图像上绘制文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文