如何在vb.net中将字符串数据写入tiff文件

时间:2010-08-13 10:49:09

标签: vb.net

我需要写一些字符串到tiff文件的数据。我正在以下列方式做事

Dim OFile As System.IO.File
Dim OWrite As system.IO.TextWriter
OWrite = OFile.CreateText("Signature.tiff")
OWrite.Write(ControlData)
MessageBox.Show("Signature is recieved and it is saved in Signature.tiff")

ControlData是要写入文件的字符串。 我正在捕获用户的签名。这个函数以字符串格式获取数据,我需要使用字符串数据创建一个tiff文件。

当我这样做的时候,创建了signature.tiff但是当我打开图像时它没有提供预览。

你能告诉我这是什么问题或正确的方法吗?

非常感谢。

2 个答案:

答案 0 :(得分:1)

Dim format As StringFormat = New StringFormat()

Dim MyRect As Rectangle = New Rectangle(0, 0, 400, 400)
Dim MyGraphics As Graphics = Me.CreateGraphics()
Dim MyImg As Image = New Bitmap(MyRect.Width, MyRect.Height, MyGraphics)
Dim imageGraphics As Graphics = Graphics.FromImage(MyImg)
imageGraphics.FillRectangle(Brushes.White, MyRect)

format.Alignment = StringAlignment.Center
format.LineAlignment = StringAlignment.Center
imageGraphics.DrawString("Hello Everyone", objFont, Brushes.Black, RectangleF.op_Implicit(MyRect))

MyGraphics.DrawImage(MyImg, MyRect)

MyImg.Save(filename)

看到这可能会帮助大家将文本字符串转换为图像。 感谢。

答案 1 :(得分:0)

TIFF文件是二进制图像文件。您正在将字符串写入文本文件。尝试在记事本中打开文件进行检查。

您需要一种在内存中创建图像并将其保存为TIFF格式的方法。

您可以使用PictureBox控件。 Write the string onto the PictureBox然后save as a TIFF