winfrom,在图片上绘制文字

2024-11-27 09:48:59
推荐回答(2个)
回答1:

//加文字水印,注意,这里的代码和以下加图片水印的代码不能共存
System.Drawing.Image image = System.Drawing.Image.FromFile(path);
Graphics g = Graphics.FromImage(image);
g.DrawImage(image, 0, 0, image.Width, image.Height);
Font f = new Font("Verdana", 32);
Brush b = new SolidBrush(Color.White);
string addText = AddText.Value.Trim();
g.DrawString(addText, f, b, 10, 10);
g.Dispose();

//加图片水印
System.Drawing.Image image = System.Drawing.Image.FromFile(path);
System.Drawing.Image copyImage = System.Drawing.Image.FromFile( Server.MapPath(".") + "/Alex.gif");
Graphics g = Graphics.FromImage(image);
g.DrawImage(copyImage, new Rectangle(image.Width-copyImage.Width, image.Height-copyImage.Height, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel);
g.Dispose();

//保存加水印过后的图片,删除原始图片
string newPath = Server.MapPath(".") + "/UploadFile/" + fileName + "_new" + extension;
image.Save(newPath);
image.Dispose();
if(File.Exists(path))
{
File.Delete(path);
}

Response.Redirect(newPath);
}
}

回答2:

System.Drawing.Pen myPen = newSystem.Drawing.Pen(System.Drawing.Color.Red);
System.Drawing.GraphicsformGraphics = this.CreateGraphics();
formGraphics.DrawLine(myPen, 0,0, 200, 200);
你写一个winform然后放在win_lod里面
我画的是一个红色的斜线
这个东西比较复杂,主要是对坐标的控制,要和你的数据哭的数据对应
这个东西说