PictureBox Question

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

    #1

    PictureBox Question

    Hi,
    I have a table which contains a BLOB field for image. I would like
    to copy a picture from
    database directly to a picture box control and I have tried the
    following:

    Dim c as Integer
    c = sDataSet.Tables (0).Rows.Count

    Dim bytBLOBData() As Byte =
    sDataSet.Tables (0).Rows(c-1)("Image")
    Dim stmBLOBData As New System.IO.Memor yStream(bytBLOB Data)

    I get the error "Invalid Parameter user" after the following line:
    Me.PictureBox2. Image = Image.FromStrea m(stmBLOBData)

    I also tried changing the following line - still "Invalid Parameter
    user" error.
    Dim bytBLOBData() As Byte =
    CType(sDataSet. Tables(0).Rows( c-1)("Image"), Byte())

    Can anyone give me an idea please, thanks in advance.

    Regards.

  • guy

    #2
    RE: PictureBox Question

    wandii,
    try reading the data from your blob into a SqlBinary, and using this to
    contruct your memory stream using the SqlBinarys Value property

    hth

    "wandii" wrote:
    [color=blue]
    > Hi,
    > I have a table which contains a BLOB field for image. I would like
    > to copy a picture from
    > database directly to a picture box control and I have tried the
    > following:
    >
    > Dim c as Integer
    > c = sDataSet.Tables (0).Rows.Count
    >
    > Dim bytBLOBData() As Byte =
    > sDataSet.Tables (0).Rows(c-1)("Image")
    > Dim stmBLOBData As New System.IO.Memor yStream(bytBLOB Data)
    >
    > I get the error "Invalid Parameter user" after the following line:
    > Me.PictureBox2. Image = Image.FromStrea m(stmBLOBData)
    >
    > I also tried changing the following line - still "Invalid Parameter
    > user" error.
    > Dim bytBLOBData() As Byte =
    > CType(sDataSet. Tables(0).Rows( c-1)("Image"), Byte())
    >
    > Can anyone give me an idea please, thanks in advance.
    >
    > Regards.
    >
    >[/color]

    Comment

    • wandii

      #3
      Re: PictureBox Question

      Hi guy,
      Thanks for the reply. I am not familiar with the SqlBinary could
      you please give
      me a small example on this. Thanks in advance.



      guy wrote:[color=blue]
      > wandii,
      > try reading the data from your blob into a SqlBinary, and using this to
      > contruct your memory stream using the SqlBinarys Value property
      >
      > hth
      >[/color]

      Comment

      • wandii

        #4
        Re: PictureBox Question

        Hi guy,
        Thanks for the reply. I am not familiar with the SqlBinary could
        you please give
        me a small example on this. Thanks in advance.



        guy wrote:[color=blue]
        > wandii,
        > try reading the data from your blob into a SqlBinary, and using this to
        > contruct your memory stream using the SqlBinarys Value property
        >
        > hth
        >[/color]

        Comment

        • wandii

          #5
          Re: PictureBox Question

          Hi guy,
          Thanks for the reply. I am not familiar with the SqlBinary could
          you please give
          me a small example on this. Thanks in advance.



          guy wrote:[color=blue]
          > wandii,
          > try reading the data from your blob into a SqlBinary, and using this to
          > contruct your memory stream using the SqlBinarys Value property
          >
          > hth
          >[/color]

          Comment

          • gene kelley

            #6
            Re: PictureBox Question

            On 28 Jun 2006 08:32:58 -0700, "wandii" <wandii@yahoo.c om> wrote:
            [color=blue]
            >Hi,
            > I have a table which contains a BLOB field for image. I would like
            >to copy a picture from
            >database directly to a picture box control and I have tried the
            >following:
            >
            > Dim c as Integer
            > c = sDataSet.Tables (0).Rows.Count
            >
            > Dim bytBLOBData() As Byte =
            >sDataSet.Table s(0).Rows(c-1)("Image")
            > Dim stmBLOBData As New System.IO.Memor yStream(bytBLOB Data)
            >
            >I get the error "Invalid Parameter user" after the following line:
            > Me.PictureBox2. Image = Image.FromStrea m(stmBLOBData)
            >
            >I also tried changing the following line - still "Invalid Parameter
            >user" error.
            > Dim bytBLOBData() As Byte =
            >CType(sDataSet .Tables(0).Rows (c-1)("Image"), Byte())
            >
            >Can anyone give me an idea please, thanks in advance.
            >
            >Regards.[/color]


            This example reads a Blob in an Access database from the field named
            "ImgData" and displays the result in PictureBox1.

            Dim mStream As New System.IO.Memor yStream
            Dim pData() As Byte = _
            DirectCast(tblS at.Rows(idxRow) .Item("ImgData" ), Byte())
            mStream.Write(p Data, 0, Convert.ToInt32 (pData.Length))
            Dim bm As Bitmap = New Bitmap(mStream, False)
            PictureBox1.Ima ge = bm
            mStream.Dispose ()

            Gene

            Comment

            • GhostInAK

              #7
              Re: PictureBox Question

              Hello gene,

              If the image is stored as an OLE image you will need to start reading at
              byte 78 instead of byte 0.

              -Boo
              [color=blue]
              > On 28 Jun 2006 08:32:58 -0700, "wandii" <wandii@yahoo.c om> wrote:
              >[color=green]
              >> Hi,
              >> I have a table which contains a BLOB field for image. I would like
              >> to copy a picture from
              >> database directly to a picture box control and I have tried the
              >> following:
              >> Dim c as Integer
              >> c = sDataSet.Tables (0).Rows.Count
              >> Dim bytBLOBData() As Byte =
              >> sDataSet.Tables (0).Rows(c-1)("Image")
              >> Dim stmBLOBData As New System.IO.Memor yStream(bytBLOB Data)
              >> I get the error "Invalid Parameter user" after the following line:
              >> Me.PictureBox2. Image = Image.FromStrea m(stmBLOBData)
              >>
              >> I also tried changing the following line - still "Invalid Parameter
              >> user" error.
              >> Dim bytBLOBData() As Byte =
              >> CType(sDataSet. Tables(0).Rows( c-1)("Image"), Byte())
              >> Can anyone give me an idea please, thanks in advance.
              >>
              >> Regards.
              >>[/color]
              > This example reads a Blob in an Access database from the field named
              > "ImgData" and displays the result in PictureBox1.
              >
              > Dim mStream As New System.IO.Memor yStream
              > Dim pData() As Byte = _
              > DirectCast(tblS at.Rows(idxRow) .Item("ImgData" ), Byte())
              > mStream.Write(p Data, 0, Convert.ToInt32 (pData.Length))
              > Dim bm As Bitmap = New Bitmap(mStream, False)
              > PictureBox1.Ima ge = bm
              > mStream.Dispose ()
              > Gene
              >[/color]


              Comment

              • gene kelley

                #8
                Re: PictureBox Question

                On Wed, 28 Jun 2006 22:19:43 +0000 (UTC), GhostInAK
                <ghostinak@gmai l.com> wrote:
                [color=blue]
                >Hello gene,
                >
                >If the image is stored as an OLE image you will need to start reading at
                >byte 78 instead of byte 0.
                >
                >-Boo
                >[/color]

                Yes. Somehow I always equate "BLOB" with "0" and Image/Picture with
                "78".

                Gene


                [color=blue][color=green]
                >> On 28 Jun 2006 08:32:58 -0700, "wandii" <wandii@yahoo.c om> wrote:
                >>[color=darkred]
                >>> Hi,
                >>> I have a table which contains a BLOB field for image. I would like
                >>> to copy a picture from
                >>> database directly to a picture box control and I have tried the
                >>> following:
                >>> Dim c as Integer
                >>> c = sDataSet.Tables (0).Rows.Count
                >>> Dim bytBLOBData() As Byte =
                >>> sDataSet.Tables (0).Rows(c-1)("Image")
                >>> Dim stmBLOBData As New System.IO.Memor yStream(bytBLOB Data)
                >>> I get the error "Invalid Parameter user" after the following line:
                >>> Me.PictureBox2. Image = Image.FromStrea m(stmBLOBData)
                >>>
                >>> I also tried changing the following line - still "Invalid Parameter
                >>> user" error.
                >>> Dim bytBLOBData() As Byte =
                >>> CType(sDataSet. Tables(0).Rows( c-1)("Image"), Byte())
                >>> Can anyone give me an idea please, thanks in advance.
                >>>
                >>> Regards.
                >>>[/color]
                >> This example reads a Blob in an Access database from the field named
                >> "ImgData" and displays the result in PictureBox1.
                >>
                >> Dim mStream As New System.IO.Memor yStream
                >> Dim pData() As Byte = _
                >> DirectCast(tblS at.Rows(idxRow) .Item("ImgData" ), Byte())
                >> mStream.Write(p Data, 0, Convert.ToInt32 (pData.Length))
                >> Dim bm As Bitmap = New Bitmap(mStream, False)
                >> PictureBox1.Ima ge = bm
                >> mStream.Dispose ()
                >> Gene
                >>[/color]
                >[/color]

                Comment

                • Dennis

                  #9
                  Re: PictureBox Question

                  Thanks for great example of reading Blob and/or OLE Image. Do you have an
                  example of how to write from a picture box image to the datatable? Thanks.
                  --
                  Dennis in Houston


                  "gene kelley" wrote:
                  [color=blue]
                  > On Wed, 28 Jun 2006 22:19:43 +0000 (UTC), GhostInAK
                  > <ghostinak@gmai l.com> wrote:
                  >[color=green]
                  > >Hello gene,
                  > >
                  > >If the image is stored as an OLE image you will need to start reading at
                  > >byte 78 instead of byte 0.
                  > >
                  > >-Boo
                  > >[/color]
                  >
                  > Yes. Somehow I always equate "BLOB" with "0" and Image/Picture with
                  > "78".
                  >
                  > Gene
                  >
                  >
                  >[color=green][color=darkred]
                  > >> On 28 Jun 2006 08:32:58 -0700, "wandii" <wandii@yahoo.c om> wrote:
                  > >>
                  > >>> Hi,
                  > >>> I have a table which contains a BLOB field for image. I would like
                  > >>> to copy a picture from
                  > >>> database directly to a picture box control and I have tried the
                  > >>> following:
                  > >>> Dim c as Integer
                  > >>> c = sDataSet.Tables (0).Rows.Count
                  > >>> Dim bytBLOBData() As Byte =
                  > >>> sDataSet.Tables (0).Rows(c-1)("Image")
                  > >>> Dim stmBLOBData As New System.IO.Memor yStream(bytBLOB Data)
                  > >>> I get the error "Invalid Parameter user" after the following line:
                  > >>> Me.PictureBox2. Image = Image.FromStrea m(stmBLOBData)
                  > >>>
                  > >>> I also tried changing the following line - still "Invalid Parameter
                  > >>> user" error.
                  > >>> Dim bytBLOBData() As Byte =
                  > >>> CType(sDataSet. Tables(0).Rows( c-1)("Image"), Byte())
                  > >>> Can anyone give me an idea please, thanks in advance.
                  > >>>
                  > >>> Regards.
                  > >>>
                  > >> This example reads a Blob in an Access database from the field named
                  > >> "ImgData" and displays the result in PictureBox1.
                  > >>
                  > >> Dim mStream As New System.IO.Memor yStream
                  > >> Dim pData() As Byte = _
                  > >> DirectCast(tblS at.Rows(idxRow) .Item("ImgData" ), Byte())
                  > >> mStream.Write(p Data, 0, Convert.ToInt32 (pData.Length))
                  > >> Dim bm As Bitmap = New Bitmap(mStream, False)
                  > >> PictureBox1.Ima ge = bm
                  > >> mStream.Dispose ()
                  > >> Gene
                  > >>[/color]
                  > >[/color]
                  >[/color]

                  Comment

                  • gene kelley

                    #10
                    Re: PictureBox Question

                    On Thu, 29 Jun 2006 17:18:02 -0700, Dennis
                    <Dennis@discuss ions.microsoft. com> wrote:
                    [color=blue]
                    >Thanks for great example of reading Blob and/or OLE Image. Do you have an
                    >example of how to write from a picture box image to the datatable? Thanks.[/color]

                    Assume loading a PictureBox Image from a file (strFilename)

                    Dim myStream As IO.FileStream = New IO.FileStream(s trFilename, _
                    IO.FileMode.Ope n, IO.FileAccess.R ead)
                    With myStream
                    Dim myImageBuffer(C Type(.Length, Integer)) As Byte
                    .Read(myImageBu ffer, 0, Convert.ToInt32 (.Length))

                    'Display the image
                    Dim PreviewlImage As Bitmap = New Bitmap(myStream )
                    me.PictureBox.I mage = PreviewImage

                    'myImageBuffer is the BLOB
                    'Pass it to whatever Insert/Update method you are using
                    'Or you can store it in the Tag property for later use
                    Me.PictureBox.T ag = myImageBuffer

                    .Close()
                    End With


                    Tag usage:
                    Dim ImgData() As Byte = DirectCast(Me.P ictureBox.Tag, Byte())

                    where ImgData() is what goes into the Blob field in the table.

                    Gene

                    Comment

                    • Dennis

                      #11
                      Re: PictureBox Question

                      Thanks for the technique.
                      --
                      Dennis in Houston


                      "gene kelley" wrote:
                      [color=blue]
                      > On Thu, 29 Jun 2006 17:18:02 -0700, Dennis
                      > <Dennis@discuss ions.microsoft. com> wrote:
                      >[color=green]
                      > >Thanks for great example of reading Blob and/or OLE Image. Do you have an
                      > >example of how to write from a picture box image to the datatable? Thanks.[/color]
                      >
                      > Assume loading a PictureBox Image from a file (strFilename)
                      >
                      > Dim myStream As IO.FileStream = New IO.FileStream(s trFilename, _
                      > IO.FileMode.Ope n, IO.FileAccess.R ead)
                      > With myStream
                      > Dim myImageBuffer(C Type(.Length, Integer)) As Byte
                      > .Read(myImageBu ffer, 0, Convert.ToInt32 (.Length))
                      >
                      > 'Display the image
                      > Dim PreviewlImage As Bitmap = New Bitmap(myStream )
                      > me.PictureBox.I mage = PreviewImage
                      >
                      > 'myImageBuffer is the BLOB
                      > 'Pass it to whatever Insert/Update method you are using
                      > 'Or you can store it in the Tag property for later use
                      > Me.PictureBox.T ag = myImageBuffer
                      >
                      > .Close()
                      > End With
                      >
                      >
                      > Tag usage:
                      > Dim ImgData() As Byte = DirectCast(Me.P ictureBox.Tag, Byte())
                      >
                      > where ImgData() is what goes into the Blob field in the table.
                      >
                      > Gene
                      >[/color]

                      Comment

                      Working...