|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
PictureBox QuestionI 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. 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. > > 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 > 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 > 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 >
Show quote
Hide quote
On 28 Jun 2006 08:32:58 -0700, "wandii" <wan***@yahoo.com> wrote: This example reads a Blob in an Access database from the field named>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. "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 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 > On Wed, 28 Jun 2006 22:19:43 +0000 (UTC), GhostInAK
<ghosti***@gmail.com> wrote: >Hello gene, Yes. Somehow I always equate "BLOB" with "0" and Image/Picture with> >If the image is stored as an OLE image you will need to start reading at >byte 78 instead of byte 0. > >-Boo > "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 >> > 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. -- Show quoteHide quoteDennis in Houston "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 > >> > > > 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 Assume loading a PictureBox Image from a file (strFilename)>example of how to write from a picture box image to the datatable? Thanks. 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 Thanks for the technique.
-- Show quoteHide quoteDennis in Houston "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 > |
|||||||||||||||||||||||