社区
C#
帖子详情
如何在一张图片上面输出文字?文字要显示在图片的中央对齐,谢谢!
zdq801104
2005-09-09 02:39:01
RT
...全文
521
13
打赏
收藏
如何在一张图片上面输出文字?文字要显示在图片的中央对齐,谢谢!
RT
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
13 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
zdq801104
2005-09-13
打赏
举报
回复
很感谢各位的技术支持,揭贴!谢谢!
accpedu
2005-09-09
打赏
举报
回复
学习。。。。
TechEye
2005-09-09
打赏
举报
回复
Bitmap 在 System.Drawing 命名空间下面.
你的PictureBox.Image是不是null的??如果你只是想在pictureBox上面画,那么只要在它的OnPaint事件加入如下代码,不会有错的!
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
string text = "这是要绘制的文本!";
Font font = new Font("宋体", 12);
Brush brush = new SolidBrush(Color.Blue);
SizeF sizeText = g.MeasureString(text, font);
int w = pictureBox1.Width;
int h = pictureBox1.Height;
g.DrawString(text, font, brush, (w - sizeText.Width) / 2, (h - sizeText.Height) / 2);
}
zdq801104
2005-09-09
打赏
举报
回复
很感谢各位的回复,特别感谢 pupo(泡泡) 兄弟,已经可以实现了,不过还想看看鼎鼎的回答,过两天揭贴
Samen168
2005-09-09
打赏
举报
回复
都说完了^-^
pupo
2005-09-09
打赏
举报
回复
Brush是个抽象类,不能实例化. 主要输入个.后顺手就选了Brush
System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
pupo
2005-09-09
打赏
举报
回复
System.Drawing.SolidBrushbrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
写错了,呵呵!
zdq801104
2005-09-09
打赏
举报
回复
我想问问鼎鼎兄弟,哪个BMP对象是哪个呢?请帮帮忙
zdq801104
2005-09-09
打赏
举报
回复
首先多谢楼上各位的回复
to : weisunding(鼎鼎) ( )
我的代码是这样的,但是编译的时候不过
Image bmp=pictureBox1.Image;
Graphics g = Graphics.FromImage(bmp);
string text = "这是要绘制的文本!";
Font font = new Font("宋体", 12);
Brush brush = new SolidBrush(Color.Blue);
SizeF sizeText = g.MeasureString(text, font);
int w = bmp.Width;
int h = bmp.Height;
g.DrawString(text, font, brush, (w - sizeText.Width) / 2, (h - sizeText.Height) / 2);
TO : pupo(泡泡)
我按照你的方法去做,但是也出现错误,错误是无法创建new System.Drawing.Brush实例,
请各位再帮帮忙
伴老思源
2005-09-09
打赏
举报
回复
不错,比我的高明多,我就不献丑了,记下了
pupo
2005-09-09
打赏
举报
回复
RectangleF 设置成你的图片大小即可
pupo
2005-09-09
打赏
举报
回复
System.Drawing.StringFormat format = new System.Drawing.StringFormat();
format.LineAlignment = System.Drawing.StringAlignment.Center ;
format.Alignment = System.Drawing.StringAlignment.Center ;
System.Drawing.Brush brush = new System.Drawing.Brush(System.Drawing.Color.Black);
g.DrawString(this.Text, this.Font, brush, new System.Drawing.RectangleF(0, 0, this.Width, this.Height), format);
brush.Dispose();
TechEye
2005-09-09
打赏
举报
回复
设你的图片对象为 bmp
Graphics g = Graphics.FromImage(bmp);
string text = "这是要绘制的文本!";
Font font = new Font("宋体", 12);
Brush brush = new SolidBrush(Color.Blue);
SizeF sizeText = g.MeasureString(text, font);
int w = bmp.Width;
int h = bmp.Height;
g.DrawString(text, font, brush, (w - sizeText.Width) / 2, (h - sizeText.Height) / 2);
计算机基本技能测试题(第二套)1.pdf
计算机基本技能测试题(第二套)1.pdf
江苏省成人高等教育计算机基础统考操作题试卷(二).doc.pdf
江苏省成人高等教育计算机基础统考操作题试卷(二).doc.pdf
《计算机基础》试题库 已整理.pdf
《计算机基础》试题库 已整理.pdf
2021-2022计算机二级等级考试试题及答案No.13887.docx
2021-2022计算机二级等级考试试题及答案No.13887.docx
安卓自定义 View 进阶:
图片
文字
一.Canvas的常用操作速查表 操作类型 相关API 备注 绘制颜色 drawColor, drawRGB, drawARGB 使用单一颜色填充整个画布 绘制基本形状 drawPoint, drawPoints, drawLine, drawLines, drawRect, drawRoundRect
C#
111,098
社区成员
642,554
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章