Saving PointF data in MSAccess

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

    #1

    Saving PointF data in MSAccess

    VS2003 using VB.Net

    I want to be able to save drawing path data in a database.
    If I store the Points array for each GraphicsPath I can then reproduce (in
    this case) filled polygons at run time. The user will create the polygons
    initially.
    The number of points in the polygons will vary so I only want to save this
    data in one field (rectangles would have been a lot easier).

    The only way I can think of doing this is by saving the points as a string
    in a Memo field; looping through all the points in the Array and using
    GetValue to add the points to the string e.g.:
    {x=369, y=89}{x=500, y=200}{x=700, y=300}

    To retrieve the polygon at the next run time then seems a bit messy i.e. to
    extract the points from the string and get them in the PointF format e.g.:
    PointArray(intZ oneCount).SetVa lue(New PointF(369, 89), 0) (would be the
    first point)
    I can see how this can be done and I'm sure it will work but can anyone
    suggest a better way? or am I missing something blindingly obvious!

    Thanks in advance.
  • Göran Andersson

    #2
    Re: Saving PointF data in MSAccess

    How about using a binarywriter to write the values to a memorystream,
    get the byte array from the stream and use the Convert.ToBase6 4String
    method to turn it into a string?

    Keith G wrote:[color=blue]
    > VS2003 using VB.Net
    >
    > I want to be able to save drawing path data in a database.
    > If I store the Points array for each GraphicsPath I can then reproduce (in
    > this case) filled polygons at run time. The user will create the polygons
    > initially.
    > The number of points in the polygons will vary so I only want to save this
    > data in one field (rectangles would have been a lot easier).
    >
    > The only way I can think of doing this is by saving the points as a string
    > in a Memo field; looping through all the points in the Array and using
    > GetValue to add the points to the string e.g.:
    > {x=369, y=89}{x=500, y=200}{x=700, y=300}
    >
    > To retrieve the polygon at the next run time then seems a bit messy i.e. to
    > extract the points from the string and get them in the PointF format e.g.:
    > PointArray(intZ oneCount).SetVa lue(New PointF(369, 89), 0) (would be the
    > first point)
    > I can see how this can be done and I'm sure it will work but can anyone
    > suggest a better way? or am I missing something blindingly obvious!
    >
    > Thanks in advance.[/color]

    Comment

    • Cor Ligthert [MVP]

      #3
      Re: Saving PointF data in MSAccess

      Keith,

      In addition to Goran.



      I hope this helps,

      Cor

      "Keith G" <KeithG@discuss ions.microsoft. com> schreef in bericht
      news:6C60F4F6-4452-4F78-B571-1AF92B711D66@mi crosoft.com...[color=blue]
      > VS2003 using VB.Net
      >
      > I want to be able to save drawing path data in a database.
      > If I store the Points array for each GraphicsPath I can then reproduce (in
      > this case) filled polygons at run time. The user will create the polygons
      > initially.
      > The number of points in the polygons will vary so I only want to save this
      > data in one field (rectangles would have been a lot easier).
      >
      > The only way I can think of doing this is by saving the points as a string
      > in a Memo field; looping through all the points in the Array and using
      > GetValue to add the points to the string e.g.:
      > {x=369, y=89}{x=500, y=200}{x=700, y=300}
      >
      > To retrieve the polygon at the next run time then seems a bit messy i.e.
      > to
      > extract the points from the string and get them in the PointF format e.g.:
      > PointArray(intZ oneCount).SetVa lue(New PointF(369, 89), 0) (would be the
      > first point)
      > I can see how this can be done and I'm sure it will work but can anyone
      > suggest a better way? or am I missing something blindingly obvious!
      >
      > Thanks in advance.[/color]


      Comment

      • Keith G

        #4
        Re: Saving PointF data in MSAccess

        Thanks Cor and Göran

        I can see how the image data is converted into the Byte Array (and back)
        from the code example. Which is very neat.
        However, and this is the bit I'm struggling with, how do I save a
        GraphicsPath to a MemoryStream?
        Göran is suggesting using the BinaryWriter but how do I do that from a
        PointF array?

        The save and retrieve process to/from the database would therefore be:
        SAVE
        [GraphicsPath]->[BinaryWriter?]->[MemoryStream]->[Byte
        Array]->[ToBase64String]
        RETRIEVE
        [FromBase64Strin g]->[Byte
        Array]->[MemoryStream]->[BinaryReader?]->[GraphicsPath]





        "Cor Ligthert [MVP]" wrote:
        [color=blue]
        > Keith,
        >
        > In addition to Goran.
        >
        > http://www.vb-tips.com/default.aspx?...7-e68d238952a5
        >
        > I hope this helps,
        >
        > Cor
        >
        > "Keith G" <KeithG@discuss ions.microsoft. com> schreef in bericht
        > news:6C60F4F6-4452-4F78-B571-1AF92B711D66@mi crosoft.com...[color=green]
        > > VS2003 using VB.Net
        > >
        > > I want to be able to save drawing path data in a database.
        > > If I store the Points array for each GraphicsPath I can then reproduce (in
        > > this case) filled polygons at run time. The user will create the polygons
        > > initially.
        > > The number of points in the polygons will vary so I only want to save this
        > > data in one field (rectangles would have been a lot easier).
        > >
        > > The only way I can think of doing this is by saving the points as a string
        > > in a Memo field; looping through all the points in the Array and using
        > > GetValue to add the points to the string e.g.:
        > > {x=369, y=89}{x=500, y=200}{x=700, y=300}
        > >
        > > To retrieve the polygon at the next run time then seems a bit messy i.e.
        > > to
        > > extract the points from the string and get them in the PointF format e.g.:
        > > PointArray(intZ oneCount).SetVa lue(New PointF(369, 89), 0) (would be the
        > > first point)
        > > I can see how this can be done and I'm sure it will work but can anyone
        > > suggest a better way? or am I missing something blindingly obvious!
        > >
        > > Thanks in advance.[/color]
        >
        >
        >[/color]

        Comment

        • Göran Andersson

          #5
          Re: Saving PointF data in MSAccess

          The PointsF struct contains two float values; X and Y. Loop through the
          array of PointFs and write each pair of values to the BinaryWriter.

          To recreate the array you get two float values from the BinaryReader to
          create each PointF struct.

          As each float value is four bytes you can calculate the length of the
          PointF array by taking the length of the byte array and divide by eight.


          Keith G wrote:[color=blue]
          > Thanks Cor and Göran
          >
          > I can see how the image data is converted into the Byte Array (and back)
          > from the code example. Which is very neat.
          > However, and this is the bit I'm struggling with, how do I save a
          > GraphicsPath to a MemoryStream?
          > Göran is suggesting using the BinaryWriter but how do I do that from a
          > PointF array?
          >
          > The save and retrieve process to/from the database would therefore be:
          > SAVE
          > [GraphicsPath]->[BinaryWriter?]->[MemoryStream]->[Byte
          > Array]->[ToBase64String]
          > RETRIEVE
          > [FromBase64Strin g]->[Byte
          > Array]->[MemoryStream]->[BinaryReader?]->[GraphicsPath]
          >
          >
          >
          >
          >
          > "Cor Ligthert [MVP]" wrote:
          >[color=green]
          >> Keith,
          >>
          >> In addition to Goran.
          >>
          >> http://www.vb-tips.com/default.aspx?...7-e68d238952a5
          >>
          >> I hope this helps,
          >>
          >> Cor
          >>
          >> "Keith G" <KeithG@discuss ions.microsoft. com> schreef in bericht
          >> news:6C60F4F6-4452-4F78-B571-1AF92B711D66@mi crosoft.com...[color=darkred]
          >>> VS2003 using VB.Net
          >>>
          >>> I want to be able to save drawing path data in a database.
          >>> If I store the Points array for each GraphicsPath I can then reproduce (in
          >>> this case) filled polygons at run time. The user will create the polygons
          >>> initially.
          >>> The number of points in the polygons will vary so I only want to save this
          >>> data in one field (rectangles would have been a lot easier).
          >>>
          >>> The only way I can think of doing this is by saving the points as a string
          >>> in a Memo field; looping through all the points in the Array and using
          >>> GetValue to add the points to the string e.g.:
          >>> {x=369, y=89}{x=500, y=200}{x=700, y=300}
          >>>
          >>> To retrieve the polygon at the next run time then seems a bit messy i.e.
          >>> to
          >>> extract the points from the string and get them in the PointF format e.g.:
          >>> PointArray(intZ oneCount).SetVa lue(New PointF(369, 89), 0) (would be the
          >>> first point)
          >>> I can see how this can be done and I'm sure it will work but can anyone
          >>> suggest a better way? or am I missing something blindingly obvious!
          >>>
          >>> Thanks in advance.[/color]
          >>
          >>[/color][/color]

          Comment

          • Keith G

            #6
            Re: Saving PointF data in MSAccess

            I have now successfully saved and retrieved the PointF data using the
            BinaryWriter and BinaryReader.

            For anybody else that might be interested the read and write loops
            respectively have ended up like this:
            ----------
            For i = PointArray(intZ oneCount).GetLo werBound(0) To
            PointArray(intZ oneCount).GetUp perBound(0)
            pt = PointArray(intZ oneCount).GetVa lue(i)
            bt = pt.X
            bw.Write(bt)
            bt = pt.Y
            bw.Write(bt)
            Next

            For i As Integer = 0 To intPts
            intX = br.ReadSingle
            intY = br.ReadSingle
            PointArray(intZ oneCount).SetVa lue(New PointF(intX, intY), i)
            Next
            ---------------

            Thanks to Göran and Cor for your help.

            Regards..


            "Göran Andersson" wrote:
            [color=blue]
            > The PointsF struct contains two float values; X and Y. Loop through the
            > array of PointFs and write each pair of values to the BinaryWriter.
            >
            > To recreate the array you get two float values from the BinaryReader to
            > create each PointF struct.
            >
            > As each float value is four bytes you can calculate the length of the
            > PointF array by taking the length of the byte array and divide by eight.
            >
            >
            > Keith G wrote:[color=green]
            > > Thanks Cor and Göran
            > >
            > > I can see how the image data is converted into the Byte Array (and back)
            > > from the code example. Which is very neat.
            > > However, and this is the bit I'm struggling with, how do I save a
            > > GraphicsPath to a MemoryStream?
            > > Göran is suggesting using the BinaryWriter but how do I do that from a
            > > PointF array?
            > >
            > > The save and retrieve process to/from the database would therefore be:
            > > SAVE
            > > [GraphicsPath]->[BinaryWriter?]->[MemoryStream]->[Byte
            > > Array]->[ToBase64String]
            > > RETRIEVE
            > > [FromBase64Strin g]->[Byte
            > > Array]->[MemoryStream]->[BinaryReader?]->[GraphicsPath]
            > >
            > >
            > >
            > >
            > >
            > > "Cor Ligthert [MVP]" wrote:
            > >[color=darkred]
            > >> Keith,
            > >>
            > >> In addition to Goran.
            > >>
            > >> http://www.vb-tips.com/default.aspx?...7-e68d238952a5
            > >>
            > >> I hope this helps,
            > >>
            > >> Cor
            > >>
            > >> "Keith G" <KeithG@discuss ions.microsoft. com> schreef in bericht
            > >> news:6C60F4F6-4452-4F78-B571-1AF92B711D66@mi crosoft.com...
            > >>> VS2003 using VB.Net
            > >>>
            > >>> I want to be able to save drawing path data in a database.
            > >>> If I store the Points array for each GraphicsPath I can then reproduce (in
            > >>> this case) filled polygons at run time. The user will create the polygons
            > >>> initially.
            > >>> The number of points in the polygons will vary so I only want to save this
            > >>> data in one field (rectangles would have been a lot easier).
            > >>>
            > >>> The only way I can think of doing this is by saving the points as a string
            > >>> in a Memo field; looping through all the points in the Array and using
            > >>> GetValue to add the points to the string e.g.:
            > >>> {x=369, y=89}{x=500, y=200}{x=700, y=300}
            > >>>
            > >>> To retrieve the polygon at the next run time then seems a bit messy i.e.
            > >>> to
            > >>> extract the points from the string and get them in the PointF format e.g.:
            > >>> PointArray(intZ oneCount).SetVa lue(New PointF(369, 89), 0) (would be the
            > >>> first point)
            > >>> I can see how this can be done and I'm sure it will work but can anyone
            > >>> suggest a better way? or am I missing something blindingly obvious!
            > >>>
            > >>> Thanks in advance.
            > >>
            > >>[/color][/color]
            >[/color]

            Comment

            Working...