输入文字在C#中的位图图像 [英] Write text on a bitmap image in C#
本文介绍了输入文字在C#中的位图图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗯,我尝试在C#中的图像上写的,我的code是:
Well, I try to write on an image in C#, my code is:
public string WriteOnImage(Bitmap Image, string NameImage, string TextFileName)
{
string Message = "OK";
try
{
Bitmap bitMapImage = new Bitmap(Image);
using (Graphics graphImage = Graphics.FromImage(Image))
{
graphImage.SmoothingMode = SmoothingMode.AntiAlias;
string line;
// Read the file and display it line by line.
StreamReader file = new StreamReader(Resources.C_PATH_DESTINO_IMG + TextFileName);
while ((line = file.ReadLine()) != null)
{
graphImage.DrawString(line, new Font("Courier New", 15, FontStyle.Bold), SystemBrushes.WindowText, new Point(0, 0));
HttpContext.Current.Response.ContentType = "image/jpeg";
bitMapImage.Save(Resources.C_PATH_DESTINO_IMG + NameImage, ImageFormat.Jpeg);
graphImage.Dispose();
bitMapImage.Dispose();
}
file.Close();
}
return Message;
}
catch (Exception ex)
{
EventLogWrite("Error: " + ex.Message);
return Message = ex.Message;
}
}
这个方法不起作用,因为在图像上不写,请帮帮我吧。
this method doesn't work because doesn't write on the image, please help me.
PD:我很抱歉,我的英语,但我拉丁裔杰杰奥,谢谢
PD: I'm sorry for my english but I'm Latino jeje, thanks.
推荐答案
看起来你是在错误的位图绘制
It looks like you are drawing on the wrong bitmap
Bitmap bitMapImage = new Bitmap(Image);
using (Graphics graphImage = Graphics.FromImage(Image))
应
Bitmap bitMapImage = new Bitmap(Image);
using (Graphics graphImage = Graphics.FromImage(bitMapImage))
这篇关于输入文字在C#中的位图图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文