创建.NET WinForm程序,在窗体上添加一个PictureBox控件pictureBox_keleyi_com和一个Button控件button_AddStringToImage_keleyi_com。
using System;
using System.Drawing;
using System.IO;
using System.Net;
using System.Windows.Forms;
namespace Keleyi.Com
{
public partial class KeleyiImageForm : Form
{
public KeleyiImageForm()
{
InitializeComponent();
}
//按钮点击事件 jihua.cnblogs.com
private void button_AddStringToImage_keleyi_com_Click(object sender, EventArgs e)
{
HttpWebRequest request_keleyi_com = (HttpWebRequest)WebRequest.Create(@"http://keleyi.com/image/a/q9e4nvb3.jpg");
WebResponse response_keleyi = null;
Stream keleyi_com_stream = null;
response_keleyi = request_keleyi_com.GetResponse();
keleyi_com_stream = response_keleyi.GetResponseStream();
Bitmap bmp = new Bitmap(keleyi_com_stream);
Graphics g = Graphics.FromImage(bmp);
String str = "柯乐义 keleyi.com";
Font font = new Font("宋体", 16);
SolidBrush sbrush = new SolidBrush(Color.Black);
g.DrawString(str, font, sbrush, new PointF(10, 30));
MemoryStream ms = new MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
if (pictureBox_keleyi_com.Name == "pictureBox_ke"+"leyi_com")
pictureBox_keleyi_com.Image = Image.FromStream(ms);
}
}
}
程序实现在网上的图片(http://keleyi.com/image/a/q9e4nvb3.jpg)上加上字符串“柯乐义 keleyi.com”,在窗体上显示出来。
本文:http://www.cnblogs.com/jihua/p/imgaddstring.html
原文:http://keleyi.com/a/bjac/xtxyoei0.htm