<gr*********@yahoo.com> wrote in message
news:11**********************@y41g2000cwy.googlegr oups.com...
Hi,
I'm trying to convert this simple string into image:
Dim bytes() as byte()=System.text.Encoding.ascii.GetBytes("123")
Dim memStream as System.IO.MemoryStream
Dim img as image
memStream.Write(bytes,0.bytes.length)
img=image.fromstream(memStream) ' an error occurs here
vb.net returns an error: "invlaid parameter" for passing stream to the
image.
I don't want to read stream from file, as I am interested in reading
from input string (textbox).
MTIA,
Grawsha
Ok, from what I understand, you want to write a string onto a image?
Dim s As String = "123"
Dim bmp As Bitmap = New Bitmap(1, 1)
Dim canvas As Graphics = Graphics.FromImage(bmp)
Dim size As Size
Try
' Measure the string.
size = canvas.MeasureString(s, New Font("Verdana", 12))
Finally
canvas.Dispose()
bmp.Dispose()
End Try
bmp = New Bitmap(size.Width, size.Height)
canvas = Graphics.FromImage(bmp)
Try
canvas.DrawString(s, New Font("Verdana", 12))
Finally
canvas.Dispose()
End Try
' Now bmp contains the valid string.
HTH (untested code, btw, may have a few errors, but should work with minor
fixes).
Mythran