I have a column named "PictureImage" in a SQL database defined as
datatype=image. It has a Bitmap picture in it. (I verified the type by
creating an Access project and a looking at the data, which access reports
as "Bitmap Image".)
In my VB.NET app I use the following code:
Dim bytBLOBData() As Byte =
Me.datasetProduct.Tables("Product").Rows(0)("Pictu reImage")
Dim stmBLOBData As New MemoryStream(bytBLOBData)
Me.pictureProduct.Image = Image.FromStream(stmBLOBData)
The last line of code (image.fromstream) always produces an Invalid
Parameter error.
Does anyone have any working samples of similar code. I've done a Google
search and see that other folks have similar errors, but no solutions.
Gary 7 11839
Hi,
Here is a quick example. Loads the northwind databases category
names into a listbox (listbox1) and displays the image in a picture box
(picturebox1).
Dim ds As DataSet
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim strConn As String
Dim conn As SqlClient.SqlConnection
Dim daCustomer As SqlClient.SqlDataAdapter
ds = New DataSet
' strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"
'strConn &= "Data Source = Northwind.mdb;"
strConn = "Server = " + Environment.MachineName + "\VSdotNet;"
strConn &= "Database = NorthWind;"
strConn &= "Integrated Security = SSPI;"
conn = New SqlClient.SqlConnection(strConn)
daCustomer = New SqlClient.SqlDataAdapter("Select * from Categories", conn)
ds = New DataSet
daCustomer.Fill(ds, "Categories")
ListBox1.DataSource = ds.Tables("Categories")
ListBox1.DisplayMember = "CategoryName"
End Sub
Private Sub ListBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ListBox1.SelectedValueChanged
Dim dr As DataRow = ds.Tables("Categories").Rows(ListBox1.SelectedInde x)
Dim ms As New System.IO.MemoryStream
Dim bm As Bitmap
Dim arData() As Byte = dr.Item("Picture")
ms.Write(arData, 78, arData.Length - 78)
bm = New Bitmap(ms)
PictureBox1.Image = bm
End Sub
Ken
-----------------
"Gary Shell" <gs****@fuse.net> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I have a column named "PictureImage" in a SQL database defined as
datatype=image. It has a Bitmap picture in it. (I verified the type by
creating an Access project and a looking at the data, which access reports
as "Bitmap Image".)
In my VB.NET app I use the following code:
Dim bytBLOBData() As Byte =
Me.datasetProduct.Tables("Product").Rows(0)("Pictu reImage")
Dim stmBLOBData As New MemoryStream(bytBLOBData)
Me.pictureProduct.Image = Image.FromStream(stmBLOBData)
The last line of code (image.fromstream) always produces an Invalid
Parameter error.
Does anyone have any working samples of similar code. I've done a Google
search and see that other folks have similar errors, but no solutions.
Gary
Looks like the key here is that you are dropping the first 78 bytes of the
image retrieved from the image that Access stored and creating the image
from that data.
After I left the note I realized that even though I was using a SQL Server
to store the data and Access was pointing to that database, that Access was
adding an OLE wrapper around the image and then storing it. The VB.net code
didn't know about that and rejected the image. Your trick would have worked
, I think.
But what I did was implement a paste from clipboard function in the picture
box and the ability to save the picture box image to the database, all in
the VB.NET code. Now I don't rely on Access to add the pictures to the
database. Images that I save this way work fine with the original code.
And I don't have to worry about those pesky 78 bytes!
Thanks though!
Gary
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:u$*************@TK2MSFTNGP15.phx.gbl... Hi,
Here is a quick example. Loads the northwind databases category names into a listbox (listbox1) and displays the image in a picture box (picturebox1).
Dim ds As DataSet
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strConn As String
Dim conn As SqlClient.SqlConnection
Dim daCustomer As SqlClient.SqlDataAdapter
ds = New DataSet
' strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"
'strConn &= "Data Source = Northwind.mdb;"
strConn = "Server = " + Environment.MachineName + "\VSdotNet;"
strConn &= "Database = NorthWind;"
strConn &= "Integrated Security = SSPI;"
conn = New SqlClient.SqlConnection(strConn)
daCustomer = New SqlClient.SqlDataAdapter("Select * from Categories",
conn) ds = New DataSet
daCustomer.Fill(ds, "Categories")
ListBox1.DataSource = ds.Tables("Categories")
ListBox1.DisplayMember = "CategoryName"
End Sub Private Sub ListBox1_SelectedValueChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles ListBox1.SelectedValueChanged
Dim dr As DataRow = ds.Tables("Categories").Rows(ListBox1.SelectedInde x)
Dim ms As New System.IO.MemoryStream
Dim bm As Bitmap
Dim arData() As Byte = dr.Item("Picture")
ms.Write(arData, 78, arData.Length - 78)
bm = New Bitmap(ms)
PictureBox1.Image = bm
End Sub Ken
----------------- "Gary Shell" <gs****@fuse.net> wrote in message news:%2****************@TK2MSFTNGP14.phx.gbl... I have a column named "PictureImage" in a SQL database defined as datatype=image. It has a Bitmap picture in it. (I verified the type by creating an Access project and a looking at the data, which access reports as "Bitmap Image".)
In my VB.NET app I use the following code: Dim bytBLOBData() As Byte = Me.datasetProduct.Tables("Product").Rows(0)("Pictu reImage")
Dim stmBLOBData As New MemoryStream(bytBLOBData)
Me.pictureProduct.Image = Image.FromStream(stmBLOBData) The last line of code (image.fromstream) always produces an Invalid Parameter error.
Does anyone have any working samples of similar code. I've done a Google search and see that other folks have similar errors, but no solutions.
Gary
Thanks all!
Is it possible to tell when to drop the 78 bytes and when NOT to? Is there
any way to determine at run time if a particular image does or does not have
the extra 78 bytes from the OLE wrapper?
Gary
"Cor Ligthert" <no************@planet.nl> wrote in message
news:Oh*************@TK2MSFTNGP12.phx.gbl... Herfried,
In my opinion is nothing wrong with the sample from Gary, except when
there is an Object Linked Embeded image used.
Your samples are not different than his code. While Ken's shows an sample wiht the offset that Gary can use. (The offset is as well in your second sample, however not is told why and what).
Just as attention for the next time.
Cor
Gary,
As I remember me, can you see that in the byte Array, however I have not
documented that.
Just debug and see what is it in the quickwatch.
Cor
Cor,
Unfortunately I converted all of my images to the non-OLE form and don't
have an instance of Northwind installed.
If you'd be so kind as to capture the first 78 bytes for me I'll try to
dissect it. (Ideally from two or three images so I can compare.)
Thanks,
Gary
"Cor Ligthert" <no************@planet.nl> wrote in message
news:eu**************@TK2MSFTNGP12.phx.gbl... Gary,
As I remember me, can you see that in the byte Array, however I have not documented that.
Just debug and see what is it in the quickwatch.
Cor
Gary,
I made a sample just in general.
I think with this you see how you can do it.
\\\needs a form with two textboxes
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles MyBase.Load
Dim conn As New SqlClient.SqlConnection("Server=Kamer;" & _
"DataBase=Northwind; Integrated Security=SSPI")
Dim sqlstr As String = _
String.Format("SELECT Photo FROM Employees WHERE EmployeeID = 1")
Dim cmd As New SqlClient.SqlCommand(sqlstr, conn)
conn.Open()
Dim rdr As SqlClient.SqlDataReader = cmd.ExecuteReader()
rdr.Read()
Dim arrImage() As Byte = DirectCast(rdr.Item("Photo"), Byte())
Dim enc As System.Text.Encoding = System.Text.Encoding.ASCII
Dim str As String = enc.GetString(arrImage, 0, 78)
TextBox1.Text = str.Replace(chr(0), "."c)
Dim sb As New System.Text.StringBuilder
For Each chr As Char In str
sb.Append(Asc(chr).ToString)
Next
TextBox2.Text = sb.ToString
rdr.Close()
conn.Close()
End Sub
///
The result from this was
Textbox1
/....
....!.Bitmap Image.Paint.Picture.........PBrush......... T..
See that I replaced the zeros by dots to get it printable
Textbox2
21284702000130140200330127127127127661051161099711 23273109971031010809710511011646801059911611711410 101500200070008066114117115104000000000328400
I hope this helps a little bit?
Cor
Thank you. Thank you! THANK YOU!
That does help. I need to compare against the non ole images but it looks
like it should be pretty easy to determine if the OLE wrapper is there by
looking for "Bitmap Image.Paint.Picture" in the first 78 bytes.
I'm going to look around and see if I can find any more info on the format
of this OLE wrapper to see if there might be other such strings to test for.
Something in the pit of my stomach tells me there just might be!
Gary
"Cor Ligthert" <no************@planet.nl> wrote in message
news:en**************@TK2MSFTNGP10.phx.gbl... Gary,
I made a sample just in general. I think with this you see how you can do it.
\\\needs a form with two textboxes Private Sub Form1_Load(ByVal sender As System.Object, ByVal _ e As System.EventArgs) Handles MyBase.Load Dim conn As New SqlClient.SqlConnection("Server=Kamer;" & _ "DataBase=Northwind; Integrated Security=SSPI") Dim sqlstr As String = _ String.Format("SELECT Photo FROM Employees WHERE EmployeeID = 1") Dim cmd As New SqlClient.SqlCommand(sqlstr, conn) conn.Open() Dim rdr As SqlClient.SqlDataReader = cmd.ExecuteReader() rdr.Read() Dim arrImage() As Byte = DirectCast(rdr.Item("Photo"), Byte()) Dim enc As System.Text.Encoding = System.Text.Encoding.ASCII Dim str As String = enc.GetString(arrImage, 0, 78) TextBox1.Text = str.Replace(chr(0), "."c) Dim sb As New System.Text.StringBuilder For Each chr As Char In str sb.Append(Asc(chr).ToString) Next TextBox2.Text = sb.ToString rdr.Close() conn.Close() End Sub ///
The result from this was
Textbox1
/.... ...!.Bitmap Image.Paint.Picture.........PBrush......... T..
See that I replaced the zeros by dots to get it printable
Textbox2
21284702000130140200330127127127127661051161099711 23273109971031010809710511
01164680105991161171141010150020007000806611411711 5104000000000328400 I hope this helps a little bit?
Cor
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Alberto |
last post by:
I'm trying to load an image in a PictureBox but I want the PictureBox has
always the same size and if the image is bigger, show a scrollBars.
How can I do it?
Thank you
|
by: marco |
last post by:
I'm a newbie and i'm doing a little application that open image. I don't
understand what i've to do to have a zoom of an image...i don't know where's
the error. If anyone know a simple code tell me...
|
by: marco |
last post by:
I'm a newbie and i'm doing a little application in C# for a Pocket PC that
open image. I don't
understand what i've to do to have a zoom of an image...i don't know where's
the error. If anyone...
|
by: Patrick Dugan |
last post by:
Hello,
I'm trying to load different images (icons) into a PictureBox1.Image.
The first image loads just fine, but the second image always returns the
error "Invalid property used."
It doesn't...
|
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...
|
by: lgbjr |
last post by:
Hello All,
I¡¯m using a context menu associated with some pictureboxes to provide
copy/paste functionality. Copying the image to the clipboard was easy. But
pasting an image from the clipboard...
|
by: John Swan |
last post by:
Hello.
I'm trying to create a simple program that amongst other things creates a
thumbnail of an image (Bitmap) to a set size determined by the user in
pixels?
The problem is: All of the...
|
by: rodchar |
last post by:
hey all,
i have an image that i want to put on my form and was just wondering if
there is a way to take away the white background on the image (make it
transparent)?
thanks,
rodchar
|
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...
|
by: Andrzej |
last post by:
I have a picturebox on my C# .NET form. The picturebox size mode is set to
zoom. 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...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |