473,785 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
+ 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.t ext.Encoding.as cii.GetBytes("1 23")
Dim memStream as System.IO.Memor yStream
Dim img as image
memStream.Write (bytes,0.bytes. length)
img=image.froms tream(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 6659

<gr*********@ya hoo.com> wrote in message
news:11******** **************@ y41g2000cwy.goo glegroups.com.. .
Hi,

I'm trying to convert this simple string into image:

Dim bytes() as byte()=System.t ext.Encoding.as cii.GetBytes("1 23")
Dim memStream as System.IO.Memor yStream
Dim img as image
memStream.Write (bytes,0.bytes. length)
img=image.froms tream(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.FromIm age(bmp)
Dim size As Size
Try
' Measure the string.
size = canvas.MeasureS tring(s, New Font("Verdana", 12))
Finally
canvas.Dispose( )
bmp.Dispose()
End Try

bmp = New Bitmap(size.Wid th, size.Height)
canvas = Graphics.FromIm age(bmp)

Try
canvas.DrawStri ng(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.t ext.Encoding.as cii.GetBytes("1 23")

try making it either

Dim bytes as byte()=System.t ext.Encoding.as cii.GetBytes("1 23")

or

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

"iwdu15" <jmmgoalsteraty ahoodotcom> wrote in message
news:D2******** *************** ***********@mic rosoft.com...
well for one....i dont even know what this is making

Dim bytes() as byte()=System.t ext.Encoding.as cii.GetBytes("1 23")

try making it either

Dim bytes as byte()=System.t ext.Encoding.as cii.GetBytes("1 23")

or

Dim bytes() as byte=System.tex t.Encoding.asci i.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
1861
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 thumbnail would show the larger image.
4
10310
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 bytes that are not printable characters? I've tested this and it seems to work fine, but I want to make sure there isn't some condition or situation I'm not aware of that could cause problems. I'm doing this because it's easier to do some of my...
1
3744
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 a SELECT statement to convert the binary image info contained in "BITS" into simple text that I can read? What role does the BIT_LENGTH field play?
0
1767
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) and including the image syntax as per the RTF Specification, however the image is not appearing when I view the document in Word or WordPad.
18
2460
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
2361
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 Image.I think I found the reason of getting error.But I am not able to solve it I am pasting the code which I wrote The reason I think is when I am extracting the RGB value from the image,R and G will be zero everytime.But I am getting the value of...
5
23470
by: SMichal | last post by:
Hi, how can I parse string "? 20.000" to double ?
3
6013
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 (converting) thing.... please help me out .. i just uploaded images so i guess it will be of no use for you people if i put my code here ...
3
6781
by: srsaravanan | last post by:
i need coding for converting block and white image into RGB image
0
9485
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10098
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8986
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5390
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5523
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4058
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 we have to send another system
3
2890
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.