本文介绍了无法在jpg图像上键入字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hellow
$ 1 $ b Form1我添加pictureBox1它包含一个图像= Tulips.jpg,我想在10,20位置画一个字符串
但我不能
Hellow
in Form1 i add pictureBox1 it contains an image =Tulips.jpg , i want to draw a string at location 10,20
but i could not
using System.Drawing.Imaging;
//...
//...
Image MyImage;
//....
//.....
private void Form1_Load(object sender, EventArgs e)
{
MyImage = Image.FromFile("Tulips.jpg");
pictureBox1.Image = MyImage;
}
private void button1_Click(object sender, EventArgs e)
{
Graphics dc = Graphics.FromImage(pictureBox1.Image);//MyImage);
dc.DrawString("hellow", new Font("Arial", 12), new SolidBrush(Color.Black), 10, 20);//<----
dc.Dispose();
}
推荐答案
pictureBox1.Invalidate();
在您的绘制代码之后。
为了更改图像文件,您必须将图像保存为新文件。
BTW:你还应该处理你创建的Font和Brush对象。
after your draw code.
In order to change the image file, you will have to save the image to a new file.
BTW: you should also dispose the Font and Brush objects that you create.
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
//your code to draw string
}
这篇关于无法在jpg图像上键入字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!