在位图上写入文本
我有以下问题。我想在 c# windows 窗体中制作一些图形。 我想将位图读取到我的程序中,然后在此位图上写入一些文本。最后我想把这张图片加载到pictureBox中。这是我的问题。我该怎么做呢?
例如,它必须如何工作:
Bitmap a = new Bitmap(@"path\picture.bmp");
a.makeTransparent();
// ? a.writeText("some text", positionX, positionY);
pictuteBox1.Image = a;
可以这样做吗?
I have following problem. I want to make some graphics in c# windows form.
I want to read bitmap to my program and after it write some text on this bitmap. In the end I want this picture load to pictureBox. And it's my question. How can I do it?
example, how must it work:
Bitmap a = new Bitmap(@"path\picture.bmp");
a.makeTransparent();
// ? a.writeText("some text", positionX, positionY);
pictuteBox1.Image = a;
Is it possible do to?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
非常老的问题,但今天必须为应用程序构建这个问题,并发现其他答案中显示的设置不会产生干净的图像(可能是因为在以后的.Net版本中添加了新选项)。
假设您希望文本位于位图的中心,您可以这样
做
Very old question, but just had to build this for an app today and found the settings shown in other answers do not result in a clean image (possibly as new options were added in later .Net versions).
Assuming you want the text in the centre of the bitmap, you can do this:
References
您需要按顺序使用
Graphics
类写在位图上。具体来说,是
DrawString
方法之一。You need to use the
Graphics
class in order to write on the bitmap.Specifically, one of the
DrawString
methods.如果您想要换行文本,则应将文本绘制在矩形中:
请参阅:https://msdn.microsoft.com/en-us/library/baw6k39s(v=vs.110).aspx
If you want wrap your text, then you should draw your text in a rectangle:
See: https://msdn.microsoft.com/en-us/library/baw6k39s(v=vs.110).aspx