C#在图片上添加文字代码

创建.NET WinForm程序,设置项目的默认命名空间为Keleyi.Com,在窗体上添加一个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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值