Home All Groups Group Topic Archive Search About
Author
28 Jun 2006 3:32 PM
wandii
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.MemoryStream(bytBLOBData)

I get the error "Invalid Parameter user" after the following line:
        Me.PictureBox2.Image = Image.FromStream(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.

Author
28 Jun 2006 3:58 PM
guy
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

Show quoteHide quote
"wandii" 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.MemoryStream(bytBLOBData)
>
> I get the error "Invalid Parameter user" after the following line:
>         Me.PictureBox2.Image = Image.FromStream(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.
>
>
Author
28 Jun 2006 4:16 PM
wandii
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:
Show quoteHide quote
> 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
>
Author
28 Jun 2006 4:19 PM
wandii
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:
Show quoteHide quote
> 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
>
Author
28 Jun 2006 4:27 PM
wandii
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:
Show quoteHide quote
> 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
>
Author
28 Jun 2006 7:29 PM
gene kelley
Show quote Hide quote
On 28 Jun 2006 08:32:58 -0700, "wandii" <wan***@yahoo.com> 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.MemoryStream(bytBLOBData)
>
>I get the error "Invalid Parameter user" after the following line:
>        Me.PictureBox2.Image = Image.FromStream(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.MemoryStream
Dim pData() As Byte = _
    DirectCast(tblSat.Rows(idxRow).Item("ImgData"), Byte())
  mStream.Write(pData, 0, Convert.ToInt32(pData.Length))
  Dim bm As Bitmap = New Bitmap(mStream, False)
  PictureBox1.Image = bm
  mStream.Dispose()

Gene
Author
28 Jun 2006 10:19 PM
GhostInAK
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

Show quoteHide quote
> On 28 Jun 2006 08:32:58 -0700, "wandii" <wan***@yahoo.com> 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.MemoryStream(bytBLOBData)
>> I get the error "Invalid Parameter user" after the following line:
>> Me.PictureBox2.Image = Image.FromStream(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.MemoryStream
> Dim pData() As Byte = _
> DirectCast(tblSat.Rows(idxRow).Item("ImgData"), Byte())
> mStream.Write(pData, 0, Convert.ToInt32(pData.Length))
> Dim bm As Bitmap = New Bitmap(mStream, False)
> PictureBox1.Image = bm
> mStream.Dispose()
> Gene
>
Author
29 Jun 2006 12:13 AM
gene kelley
On Wed, 28 Jun 2006 22:19:43 +0000 (UTC), GhostInAK
<ghosti***@gmail.com> wrote:

>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
>

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

Gene



Show quoteHide quote
>> On 28 Jun 2006 08:32:58 -0700, "wandii" <wan***@yahoo.com> 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.MemoryStream(bytBLOBData)
>>> I get the error "Invalid Parameter user" after the following line:
>>> Me.PictureBox2.Image = Image.FromStream(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.MemoryStream
>> Dim pData() As Byte = _
>> DirectCast(tblSat.Rows(idxRow).Item("ImgData"), Byte())
>> mStream.Write(pData, 0, Convert.ToInt32(pData.Length))
>> Dim bm As Bitmap = New Bitmap(mStream, False)
>> PictureBox1.Image = bm
>> mStream.Dispose()
>> Gene
>>
>
Author
30 Jun 2006 12:18 AM
Dennis
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


Show quoteHide quote
"gene kelley" wrote:

> On Wed, 28 Jun 2006 22:19:43 +0000 (UTC), GhostInAK
> <ghosti***@gmail.com> wrote:
>
> >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
> >
>
> Yes.  Somehow I always equate "BLOB" with "0" and Image/Picture with
> "78".
>
> Gene
>
>
>
> >> On 28 Jun 2006 08:32:58 -0700, "wandii" <wan***@yahoo.com> 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.MemoryStream(bytBLOBData)
> >>> I get the error "Invalid Parameter user" after the following line:
> >>> Me.PictureBox2.Image = Image.FromStream(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.MemoryStream
> >> Dim pData() As Byte = _
> >> DirectCast(tblSat.Rows(idxRow).Item("ImgData"), Byte())
> >> mStream.Write(pData, 0, Convert.ToInt32(pData.Length))
> >> Dim bm As Bitmap = New Bitmap(mStream, False)
> >> PictureBox1.Image = bm
> >> mStream.Dispose()
> >> Gene
> >>
> >
>
Author
30 Jun 2006 5:36 AM
gene kelley
On Thu, 29 Jun 2006 17:18:02 -0700, Dennis
<Den***@discussions.microsoft.com> wrote:

>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.

Assume loading a PictureBox Image from a file (strFilename)

Dim myStream As IO.FileStream = New IO.FileStream(strFilename, _
      IO.FileMode.Open, IO.FileAccess.Read)
      With myStream
          Dim myImageBuffer(CType(.Length, Integer)) As Byte
          .Read(myImageBuffer, 0, Convert.ToInt32(.Length))

          'Display the image  
          Dim PreviewlImage As Bitmap = New Bitmap(myStream)
          me.PictureBox.Image = 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.Tag = myImageBuffer

           .Close()
      End With


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

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

Gene
Author
1 Jul 2006 12:04 AM
Dennis
Thanks for the technique.
--
Dennis in Houston


Show quoteHide quote
"gene kelley" wrote:

> On Thu, 29 Jun 2006 17:18:02 -0700, Dennis
> <Den***@discussions.microsoft.com> wrote:
>
> >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.
>
> Assume loading a PictureBox Image from a file (strFilename)

> Dim myStream As IO.FileStream = New IO.FileStream(strFilename, _
>       IO.FileMode.Open, IO.FileAccess.Read)
>       With myStream
>           Dim myImageBuffer(CType(.Length, Integer)) As Byte
>           .Read(myImageBuffer, 0, Convert.ToInt32(.Length))
>          
>           'Display the image  
>           Dim PreviewlImage As Bitmap = New Bitmap(myStream)
>           me.PictureBox.Image = 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.Tag = myImageBuffer
>
>            .Close()
>       End With
>
>
>      Tag usage:
>      Dim ImgData() As Byte = DirectCast(Me.PictureBox.Tag, Byte())   
>   
>     where ImgData() is what goes into the Blob field in the table.
>
> Gene
>