write text as image

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dragon

    #1

    write text as image

    Hi,

    Does anyone know of any examples for writing text into images? I have a
    program that collects some system information and I would like to write that
    text into a BMP or JPG file.

    Thank you.


  • Herfried K. Wagner [MVP]

    #2
    Re: write text as image

    "Dragon" <baadil_nospam@ hotmail.com> schrieb:[color=blue]
    > Does anyone know of any examples for writing text into images? I have a
    > program that collects some system information and I would like to write
    > that text into a BMP or JPG file.[/color]

    \\\
    Dim b As New Bitmap(100, 100, ...)
    Dim g As Graphics = Graphics.FromIm age(b)
    g.DrawString(.. .)
    g.Dispose()
    b.Save(...)
    b.Dispose()
    ///

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://classicvb.org/petition/>

    Comment

    • Mythran

      #3
      Re: write text as image


      "Dragon" <baadil_nospam@ hotmail.com> wrote in message
      news:O%23nuZ%23 y0FHA.1028@TK2M SFTNGP12.phx.gb l...[color=blue]
      > Hi,
      >
      > Does anyone know of any examples for writing text into images? I have a
      > program that collects some system information and I would like to write
      > that text into a BMP or JPG file.
      >
      > Thank you.
      >[/color]

      Tested this and it works ;)

      Dim img As System.Drawing. Bitmap
      Dim canvas As System.Drawing. Graphics

      ' Create a blank image.
      img = New System.Drawing. Bitmap( _
      200, _
      200, _
      System.Drawing. Imaging.PixelFo rmat.Format32bp pArgb _
      )

      Try
      ' Create the canvas.
      canvas = System.Drawing. Graphics.FromIm age(img)

      ' Paint a background.
      canvas.Clear(Sy stem.Drawing.Co lor.White)

      ' Draw the "Hello World!" string.
      canvas.DrawStri ng( _
      "Hello World!", _
      New System.Drawing. Font("Verdana", 12), _
      System.Drawing. Brushes.Black, _
      10, _
      10 _
      )

      ' Save the image to disk.
      img.Save( _
      "C:\HelloWorld. jpg", _
      System.Drawing. Imaging.ImageFo rmat.Jpeg _
      )
      img.Save( _
      "C:\HelloWorld. bmp", _
      System.Drawing. Imaging.ImageFo rmat.Bmp _
      )
      Finally
      ' Cleanup.
      If Not canvas Is Nothing
      canvas.Dispose( )
      End If
      img.Dispose()
      End Try


      HTH,
      Mythran ;)

      Comment

      • Dragon

        #4
        Re: write text as image

        Thank you everyone. I shall give it a try.


        "Mythran" <kip_potter@hot mail.comREMOVET RAIL> wrote in message
        news:uf772bz0FH A.916@TK2MSFTNG P10.phx.gbl...[color=blue]
        >
        > "Dragon" <baadil_nospam@ hotmail.com> wrote in message
        > news:O%23nuZ%23 y0FHA.1028@TK2M SFTNGP12.phx.gb l...[color=green]
        >> Hi,
        >>
        >> Does anyone know of any examples for writing text into images? I have a
        >> program that collects some system information and I would like to write
        >> that text into a BMP or JPG file.
        >>
        >> Thank you.
        >>[/color]
        >
        > Tested this and it works ;)
        >
        > Dim img As System.Drawing. Bitmap
        > Dim canvas As System.Drawing. Graphics
        >
        > ' Create a blank image.
        > img = New System.Drawing. Bitmap( _
        > 200, _
        > 200, _
        > System.Drawing. Imaging.PixelFo rmat.Format32bp pArgb _
        > )
        >
        > Try
        > ' Create the canvas.
        > canvas = System.Drawing. Graphics.FromIm age(img)
        >
        > ' Paint a background.
        > canvas.Clear(Sy stem.Drawing.Co lor.White)
        >
        > ' Draw the "Hello World!" string.
        > canvas.DrawStri ng( _
        > "Hello World!", _
        > New System.Drawing. Font("Verdana", 12), _
        > System.Drawing. Brushes.Black, _
        > 10, _
        > 10 _
        > )
        >
        > ' Save the image to disk.
        > img.Save( _
        > "C:\HelloWorld. jpg", _
        > System.Drawing. Imaging.ImageFo rmat.Jpeg _
        > )
        > img.Save( _
        > "C:\HelloWorld. bmp", _
        > System.Drawing. Imaging.ImageFo rmat.Bmp _
        > )
        > Finally
        > ' Cleanup.
        > If Not canvas Is Nothing
        > canvas.Dispose( )
        > End If
        > img.Dispose()
        > End Try
        >
        >
        > HTH,
        > Mythran ;)[/color]


        Comment

        • Bob Powell [MVP]

          #5
          Re: write text as image

          There is an example of creating high resolution image files with text in the
          GDI+ FAQ.

          --
          Bob Powell [MVP]
          Visual C#, System.Drawing

          Ramuseco Limited .NET consulting


          Find great Windows Forms articles in Windows Forms Tips and Tricks


          Answer those GDI+ questions with the GDI+ FAQ


          All new articles provide code in C# and VB.NET.
          Subscribe to the RSS feeds provided and never miss a new article.





          "Dragon" <baadil_nospam@ hotmail.com> wrote in message
          news:O%23nuZ%23 y0FHA.1028@TK2M SFTNGP12.phx.gb l...[color=blue]
          > Hi,
          >
          > Does anyone know of any examples for writing text into images? I have a
          > program that collects some system information and I would like to write
          > that text into a BMP or JPG file.
          >
          > Thank you.
          >[/color]


          Comment

          Working...