Drawing lines and saving as bitmap

Posted on 2009-02-24
Last Modified: 2013-11-26
I'm getting a signature in a PDA. Basically, I'm drawing points as the user writes their name. I'm saving those points in a text file in a database. At a web site, I want to have a web service use a function to redraw the signature and save it as a bitmap. However, I can't seem to get a graphics object to play with the way I think I'm supposed to. For example, I can
Dim PN as new Panel

But there is no pn.Graphics object like there is on the PDA. Anyways, I'm not very experienced with graphics and I need some code to show me how I can create a something (with code only) that will allow me to redraw the points that make the signature. Once I have the signature redrawn, I want to create a bitmap that I can save somewhere.
Here is some code I use in the PDA:

Private Sub FillSignature(ByVal Signature As String)

        Dim PlotX, PlotY, PlotXold, PlotYold, SigPos As Long



            'Dim file As New System.IO.StreamReader("\windows\mysig.txt")

            SigData = Signature 'file.ReadToEnd()


            SigPos = 1

            While SigPos < Len(SigData)

                PlotX = Val("&H" & Mid(SigData, SigPos, 2))

                PlotY = Val("&H" & Mid(SigData, SigPos + 2, 2))

                If PlotY > 127 Then

                    PlotXold = PlotX

                    PlotYold = PlotY - 128


          , PlotXold, PlotYold, PlotX, PlotY)

                    Me.pDrawWindow.Invalidate(New Rectangle(Math.Min(PlotX, PlotXold), Math.Min(PlotY, PlotYold), Math.Abs(PlotXold - PlotX) + 1, Math.Abs(PlotYold - PlotY) + 1))

                    PlotXold = PlotX

                    PlotYold = PlotY

                End If

                SigPos = SigPos + 4

            End While

        Catch ex As Exception

            MsgBox("Error writing signature", MsgBoxStyle.Information, "Signature error...")

            Exit Sub

        End Try

    End Sub

Open in new window

Question by:Misledman
    LVL 85

    Accepted Solution

    Some high level code on how to draw to a bitmap in VB.Net:

            Dim bmpFileName As String = "c:\someImage.bmp"
            Dim bmp As New Bitmap(yourWidthHere, yourHeightHere)
            Dim G As Graphics = Graphics.FromImage(bmp)

            ' draw with "G"...

            ' some kind of loop here:
                G.DrawLine(Pens.Black, pointA, pointB)

    LVL 85

    Expert Comment

    by:Mike Tomlinson can paint the background of the bitmap to a specified color with:

    LVL 12

    Expert Comment

    Hello, Misledman,

    Idle_Mind's suggestions are right on for creating the bitmap that you want to save.

    If you still want to draw the signature on the Panel, just use the panel's Paint event.  It provides a PaintEventArgs parameter (e) that contains the graphics (e.Graphics) on which you would draw your connected lines.

    But I wonder why you would bother to save the bitmap, when you already have all the information in the "points" text file.  This will probably be a more compact file than the bitmap, and whenever you need a bitmap to display to a user..., well you already have all of the code required to recreate it on demand.


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now