472,374 Members | 1,376 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,374 software developers and data experts.

converting string to image..??

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

Jun 30 '06 #1
3 6457

<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


Jun 30 '06 #2
well for one....i dont even know what this is making

Dim bytes() as byte()=System.text.Encoding.ascii.GetBytes("123")

try making it either

Dim bytes as byte()=System.text.Encoding.ascii.GetBytes("123")

or

Dim bytes() as byte=System.text.Encoding.ascii.GetBytes("123")
and see how that works
--
-iwdu15
Jun 30 '06 #3

"iwdu15" <jmmgoalsteratyahoodotcom> wrote in message
news:D2**********************************@microsof t.com...
well for one....i dont even know what this is making

Dim bytes() as byte()=System.text.Encoding.ascii.GetBytes("123")

try making it either

Dim bytes as byte()=System.text.Encoding.ascii.GetBytes("123")

or

Dim bytes() as byte=System.text.Encoding.ascii.GetBytes("123")
and see how that works
--
-iwdu15


His problem is that he is trying to load an image from a memory stream that
only contains the bytes of text. The FromStream method expects a byte-array
containing the bytes of an image, not the bytes of a simple string.

By loading the byte-array into an image (FromStream method) he is getting an
exception. So, to do this correctly, he needs to write the string onto an
image using the Graphics class.

HTH :)

Mythran

Jun 30 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Richard | last post by:
Considering the elemtary image swap routine in javascript: document.name.src="filename.gif" How would this be translated into PHP? So that if a visitor has js turned off, clicking on a...
4
by: Hal Vaughan | last post by:
If I have a byte and I convert it to string (String sData = new String(byte bData), then convert it back (byte bData = sData.getBytes()), will all data be intact, or do Strings have problems with...
1
by: Altemir | last post by:
I have a table that contains the following two columns: BITS (image(16)) BIT_LENGTH (int(4)) When I look at the table, I see "OLE Object" in the BITS column. What syntax should I use in...
0
by: Mark Allen | last post by:
Hello, I am creating an RTF document server side for a report. However I am having problems converting images into the required RTF format. I am converting the image into a string (binary)...
18
by: Al Bahr | last post by:
Hi Does anyone know how to convert and image to its negative? Well actually I need to convert a negative of an image to its positive I appreciate any help you can provide Thank A
1
by: retheeshnewage | last post by:
I have a doubt in php.I wrote a php program to convert colour Images to balck & white.It is working fine with JPEG files and PNG files.When it comes to GIF files I am not getting the colour...
5
by: SMichal | last post by:
Hi, how can I parse string "? 20.000" to double ?
3
by: Muddasir | last post by:
hi all i need to upload an image and if that image is coloured i need to convert it to black and white image ... till now i only uploaded images ... simple.. have no idea how to do this...
3
by: srsaravanan | last post by:
i need coding for converting block and white image into RGB image
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.