2010-08-13 112 views
1

我需要写一些字符串到tiff文件的数据。我按照以下方法做如何在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,但是当我打开图像时,它没有提供预览。

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

非常感谢。

回答

0

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

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

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

+0

您好马克,感谢您的回复我已经看过链接,但它只是高于我的头。有没有更简单的方法来做到这一点?当我使用jpg文件格式时,而不是tiff,它给了同样的错误。你能帮我解决这个问题吗? 这个问题用简单的话来说就是:数据以字符串格式存在,我必须存储并显示为图像。 你能告诉我一些方向吗? 谢谢。 – 2010-08-13 12:35:38

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) 

只是看到这可能会帮助你所有的文字字符串转换为图像。 谢谢。

相关问题