文字写在C#的图像 [英] Write Text On An Image in c#

查看:112
本文介绍了文字写在C#的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题。我想做出一些图形的位图图像像债券形式

I have following problem. I want to make some graphics in bitmap image like bond form

我可以写在图像搜索文本
但我会写在不同的位置更多的文本

i can write a text in image
but i will write more text in various positions

Bitmap a = new Bitmap(@"path\picture.bmp");

using(Graphics g = Graphics.FromImage(a))
{
 g.DrawString(....); // requires font, brush etc
}

我怎么能写的文字并进行保存,并在保存的图像写另一个文本

how can i write text and save it and write another text in saved image

推荐答案

要绘制多个字符串叫拉绳多的时候,你可以指定绘制字符串的位置。本例中我们得出两个字符串Hello,字(你好,在蓝色的前期字的红色):

To draw multiple strings call draw string multiple time, you can specify the location of the drawn string. this example we will draw two string "Hello", "Word" ("Hello" in blue color upfront "Word" in red color):

string firstText = "Hello";
string secondText = "World";

PointF firstLocation = new PointF(10f, 10f);
PointF secondLocation = new PointF(10f, 50f);

string imageFilePath = @"path\picture.bmp"
Bitmap bitmap = (Bitmap)Image.FromFile(imageFilePath);//load the image file

using(Graphics graphics = Graphics.FromImage(bitmap))
{
    using (Font arialFont =  new Font("Arial", 10))
    {
        graphics.DrawString(firstText, arialFont, Brushes.Blue, firstLocation);
        graphics.DrawString(secondText, arialFont, Brushes.Red, secondLocation);
    }
}

bitmap.Save(imageFilePath);//save the image file

编辑:我添加的加载和保存code

"I Add a load and save code".

您可以打开该位图文件的任何时间 Image.FromFile ,并绘制使用上述code上有一个新的文本。然后保存图像文件 bitmap.Save

You can open the bitmap file any time Image.FromFile, and draw a new text on it using the above code. and then save the image file bitmap.Save

这篇关于文字写在C#的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆