【问题标题】:Generating tiff file from a multi-line text box in C#从 C# 中的多行文本框生成 tiff 文件
【发布时间】:2014-01-03 04:56:36
【问题描述】:

我正在将在 Web 表单中输入的信息写入 tiff 文件。我的问题是评论框在网络表单中发挥作用的地方。注释框是多行的,在将其写入 tiff 文件时,输入到注释框中的一些信息会从 tiff 图像中掉出来。

我如何尝试将其写入 tiff 文件的代码:-

System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(800, 1000); //Creates Bitmap
Graphics g = Graphics.FromImage(bitmap);
g.DrawString("Comment: " + CommentBox.Text, outputFont, Brushes.Black, new PointF(0, 700)); // Writing the text from the comment box on to the Tiff file.

所以这对我来说意味着,如果我将多行注释写为:-

“你好测试。

你好,一次又一次的测试,一次又一次,一次又一次。

你好,一次又一次的测试,一次又一次,一次又一次。你好,一次又一次的测试,一次又一次,一次又一次。”

我的 tiff 文件仅捕获最大宽度为 1000 的行元素,超出该宽度的元素不会自动生成在新行中。

谁能帮我解决这个问题?想法?

【问题讨论】:

标签: c# tiff


【解决方案1】:

试试这样 - 你可以使用 DrawString 的重载,它接受一个包含矩形,并且文本应该包含在其中:

System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(800, 1000); //Creates Bitmap
using(Graphics g = Graphics.FromImage(bitmap))
{
   RectangleF rect = new RectangleF(new PointF(0, 700), new SizeF(200,200)); // adjust these accordingly for your bounding rect
   StringFormat drawFormat = new StringFormat();
   drawFormat.Alignment = StringAlignment.Near;
   g.DrawString("Comment: " + CommentBox.Text, outputFont, Brushes.Black, rect, drawFormat); // Writing the text from the comment box on to the Tiff file.
}

【讨论】:

  • new SizeF(200,200) 中的值是什么意思?谢谢!它有效。
  • SizeF(200,200) 指定 RectangleF 的两边都有 200 像素长。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-06-29
  • 1970-01-01
  • 2016-07-28
  • 2011-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多