473,289 Members | 2,155 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 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 6590

<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
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.