在c#中编写位图图像上的文本
本文关键字:图像 文本 位图 | 更新日期: 2023-09-27 18:02:16
嗯,我试着在c#中写一个图像,我的代码是:
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;
}
}
这个方法不工作,因为没有在图像上写,请帮助我。
PD:很抱歉我的英语不好,但我是拉丁裔jeje,谢谢。看起来你画错位图了
Bitmap bitMapImage = new Bitmap(Image);
using (Graphics graphImage = Graphics.FromImage(Image))
应该 Bitmap bitMapImage = new Bitmap(Image);
using (Graphics graphImage = Graphics.FromImage(bitMapImage))