converting string to image..??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • grawsha2000@yahoo.com

    #1

    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

  • Mythran

    #2
    Re: converting string to image..??


    <grawsha2000@ya hoo.com> wrote in message
    news:1151689186 .591214.123040@ y41g2000cwy.goo glegroups.com.. .[color=blue]
    > 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
    >[/color]

    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




    Comment

    • iwdu15

      #3
      RE: converting string to image..??

      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

      Comment

      • Mythran

        #4
        Re: converting string to image..??


        "iwdu15" <jmmgoalsteraty ahoodotcom> wrote in message
        news:D2E10E66-D28C-4500-B5A6-2BDBBDEA4061@mi crosoft.com...[color=blue]
        > 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[/color]

        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

        Comment

        Working...