Hello Everyone

I need to convert string to an image in vb.net.
In my project, i need to capture the signature and show it as image.
Capturing signature is done and it returns the data as string.
I need to take this string and show it as image.
I am doing in the following way

Dim Wfile As New StreamWriter("C:\Signature.tiff")
						
WFile.WriteLine(ControlData) 'ControlData is the captured data in string format.
WFile.Close()

The tiff file is being created... but when i clicked on that to view the image.. it is showing nothing and it says preview not available. But the size of the image is not 0. so the image has some data.

In the same way i have done in Html and VB and it worked perfectly fine. I am not able to understand why in vb.net it is giving problem.

Can anyone tell me whats wrong with this code? or Can you tell me correct way of doing it?
Please help me.
Thanks a lot.

With love and regards
Praveen.

Edited 6 Years Ago by praveenpvs: n/a

You need to use an image writer.
[ Dim format As StringFormat = New StringFormat()
Dim g as graphics
format.Alignment = StringAlignment.Center
format.LineAlignment = StringAlignment.Center
imageGraphics.DrawString("Drawing to an image", , Brushes.Black, RectangleF.op_Implicit(rect), format)
g.DrawImage(img, rect)
g.SaveImage(img,filename)]

Good luck.
JR

You need to use an image writer.
[ Dim format As StringFormat = New StringFormat()
Dim g as graphics
format.Alignment = StringAlignment.Center
format.LineAlignment = StringAlignment.Center
imageGraphics.DrawString("Drawing to an image", , Brushes.Black, RectangleF.op_Implicit(rect), format)
g.DrawImage(img, rect)
g.SaveImage(img,filename)]

Good luck.
JR

Thanks for your reply. somethings are not clear in this, please help me.
what are imagegraphics, img and rect in this code?
do we need to declare them right?
Please do tell me. This part is very important in my project.
Thanks once again.

Here you go:
[ Dim MyRect As Rectangle = New Rectangle(0, 0, 100, 100)
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.Black, MyRect)]

The missing statements
JR

Here you go:
[ Dim MyRect As Rectangle = New Rectangle(0, 0, 100, 100)
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.Black, MyRect)]

The missing statements
JR

Final code with some modifications is as follows:

Dim format As StringFormat = New StringFormat()
Dim g As graphics
Dim MyRect As Rectangle = New Rectangle(0, 0, 100, 100)
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.Black, MyRect)
'Dim imagegraphics As Image
format.Alignment = StringAlignment.Center
format.LineAlignment = StringAlignment.Center
imageGraphics.DrawString("Hello Everyone", objFont, Brushes.Black, RectangleF.op_Implicit(MyRect)) 'objfont is of type Font
'imageGraphics.DrawString("Drawing to an image", "Times New Roman", Brushes.Black, RectangleF.op_Implicit(MyRect), format) //The function has more arguments.
						
						
MyGraphics.DrawImage(MyImg, MyRect)
'g.DrawImage(MyImg, MyRect) // g does not have function by name draw image
MyImg.Save("C:\Documents and Settings\praveen_p1\Desktop\Signature.tiff")

When i ran this program, the tiff file is being created but when i opened it, one black box is seen. There is no text visible in the image.

I have attached the file with this post, please look into that.
Thanks a lot for your help.
Please help me out of this.
This is very important for my project.

Edited 6 Years Ago by praveenpvs: n/a

Don't fill the rectangle with black:

imageGraphics.FillRectangle(Brushes.Black, MyRect)

Use Brushes.White so that your text would show up. Sorry that was just a sample and meant to be only a guideline of how to do it.

JR

This article has been dead for over six months. Start a new discussion instead.