473,467 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 6621

<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: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.