我如何在 c# 或 vb.net 中向图像添加文本 [英] how do i add text to image in c# or vb.net

查看:20
本文介绍了我如何在 c# 或 vb.net 中向图像添加文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我是一名普通的 Visual Studio 程序员,我需要一个函数或例程来将文本添加到图像的按钮上,而不是像我在图像中显示的那样

am an average visual studio programmer, i need a function or routine to add text to the button of an image not on it like i showed in the image

请多多指教

  • 我使用 Visual Studio 进行编程2008 年,在 winxp 上.
  • 该应用程序是一个控制台应用程序.
  • 它将在 win2000 以上运行
  • 我会在之后保存结果图像向文件添加文本

推荐答案

  • 使用您想要的新尺寸创建位图

    • Create a bitmap with the new size you want

      复制新位图顶部的原图

      在新位图上写入你想要的文本

      Write the text you want onto the new bitmap

      像这样:(未经测试)

          var bmp = Bitmap.FromFile("orig.jpg");
          var newImage = new Bitmap(bmp.Width, bmp.Height + 50);
      
          var gr = Graphics.FromImage(newImage);
          gr.DrawImageUnscaled(bmp, 0, 0);
          gr.DrawString("this is the added text", SystemFonts.DefaultFont, Brushes.Black ,
              new RectangleF(0, bmp.Height, bmp.Width, 50));
      
          newImage.Save("newImg.jpg");
      

      这篇关于我如何在 c# 或 vb.net 中向图像添加文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆