473,385 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

Jun 28 '06 #1
10 2336
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

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

Jun 28 '06 #2
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:
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


Jun 28 '06 #3
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:
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


Jun 28 '06 #4
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:
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


Jun 28 '06 #5
On 28 Jun 2006 08:32:58 -0700, "wandii" <wa****@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
Jun 28 '06 #6
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
On 28 Jun 2006 08:32:58 -0700, "wandii" <wa****@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

Jun 28 '06 #7
On Wed, 28 Jun 2006 22:19:43 +0000 (UTC), GhostInAK
<gh*******@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" <wa****@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

Jun 29 '06 #8
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:
On Wed, 28 Jun 2006 22:19:43 +0000 (UTC), GhostInAK
<gh*******@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" <wa****@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

Jun 30 '06 #9
On Thu, 29 Jun 2006 17:18:02 -0700, Dennis
<De****@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
Jun 30 '06 #10
Thanks for the technique.
--
Dennis in Houston
"gene kelley" wrote:
On Thu, 29 Jun 2006 17:18:02 -0700, Dennis
<De****@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

Jul 1 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Stephen Williams | last post by:
Does Microsoft have a comment the possible bug on the PictureBox Class. Here is the exchange I had on the Experts-Exchange regarding this issue: From Z_Beeblebrox: Hi, I believe it is...
2
by: active | last post by:
I have a picturebox usercontrol sitting on a usercontrol. I need a KeyPress event in the PictureBox. I suppose I could have a property in the pictureBox that is accessed by a call in a...
3
by: Tom | last post by:
I have a picturebox on my VB.NET form. The picturebox size mode is set to stretched. I then load an image into that form and display it. As the user moves the mouse over the form, I want to get and...
6
by: Rich | last post by:
Hello, I want to simulate the dynamic thumbnail display of Windows Explorer (winxp) on a form or pannel container. If I place a picture box on my container form/pannel and dimension it to the...
4
by: TomA | last post by:
Hi All, I have a picturebox on a form containing the photo of a person. As you advance through the records, the photo updates. Rather than storing the images in an inefficient blob field in a...
0
by: dlamar | last post by:
I'm using VB.NET with 2.0 - I have a number of PictureBoxes in my application - all of which use a context menu to change the associated Image to one of 5 options. I need to maintain the state of...
2
by: =?Utf-8?B?Sm9uIFBhcnJ5?= | last post by:
Hi, I've got a Picturebox, into which I am putting a frame bitmap from a video camera. The camera bitmap is larger than the picturebox, which has SizeMode set to "Zoom" which causes the bitmap...
0
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Using VS2005 with .NET Framework 2.0 I'm using the the System.Windows.Forms.PictureBox to display a bitmap when the PictureBox.SizeMode is PictureBoxSizeMode.StretchImage The PictureBox can be...
5
by: AWW | last post by:
XP VB 2005 running an example from help that creates a picturebox in code - the picturebox is not created. If I comment out the "Dim Box as New PictureBox" and create it in Design mode - the...
1
by: leshka82 | last post by:
I have recently designed a Winform Image drag & drop utility. The approach I took was to have a Panel control serve as a destination for multiple file drop. Once the user dragged & dropped the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.