Image.FromStream(ms) Invalid parameter used problem!!!

E

Edward Koucherian

Hello,

I have
TABLE Picture (PictureID Int IDENTITY(1,1) NOT NULL,
FileName Varchar(255) NOT NULL,
Picture Image NOT NULL,
CONSTRAINT [PK_Picture] PRIMARY KEY CLUSTERED
(PictureID)

On Server and on Local and I'm running this code

Dim myConnection As SqlConnection
Dim selectCMD As SqlCommand
Dim typeDA As New SqlDataAdapter
Dim typeDS As DataSet = New DataSet
Dim I As Integer
myConnection = New SqlConnection("Server=server2;DataBase=aapcat;Initial
Catalog=aapcat;Integrated Security=SSPI")
myConnection.Open()
typeDA.SelectCommand = New SqlCommand("SELECT * FROM GENERAL_TYPES ORDER BY
GT_CODE", myConnection)
typeDA.SelectCommand.CommandTimeout = 30
typeDA.Fill(typeDS, "General_Types")
I = 1
Do While IsDBNull(typeDS.Tables("General_Types").Rows(I)("GT_Image")) = True
I = I + 1
Loop
If IsDBNull(typeDS.Tables("General_Types").Rows(I)("GT_Image")) = False Then
Dim arrPicture() As Byte =
typeDS.Tables("General_Types").Rows(I)("GT_Image")
Dim ms As New MemoryStream(arrPicture)
With PictureBox3
..BorderStyle = BorderStyle.Fixed3D
..SizeMode = PictureBoxSizeMode.CenterImage
..Image = Image.FromStream(ms)
End With
Else
PictureBox3.Image = Nothing
End If
myConnection.Close()

On the local it's working fine and displaying the image.
On the server it's gaving me the error

An unhandled exception of type 'System.ArgumentException' occurred in
system.drawing.dll
Additional information: Invalid parameter used.

The line is
..Image = Image.FromStream(ms)

Any help will be appreciated.
Regards
Edward Koucherian
 
K

Ken Tucker [MVP]

Hi,

The images in the northwind database are offset by 78. Maybe
the images in your database are offset also. Hope this helps. Assumes the
data is coming from a datarow dr in the picture field.

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)



Ken
---------------------------
Hello,

I have
TABLE Picture (PictureID Int IDENTITY(1,1) NOT NULL,
FileName Varchar(255) NOT NULL,
Picture Image NOT NULL,
CONSTRAINT [PK_Picture] PRIMARY KEY CLUSTERED
(PictureID)

On Server and on Local and I'm running this code

Dim myConnection As SqlConnection
Dim selectCMD As SqlCommand
Dim typeDA As New SqlDataAdapter
Dim typeDS As DataSet = New DataSet
Dim I As Integer
myConnection = New SqlConnection("Server=server2;DataBase=aapcat;Initial
Catalog=aapcat;Integrated Security=SSPI")
myConnection.Open()
typeDA.SelectCommand = New SqlCommand("SELECT * FROM GENERAL_TYPES ORDER BY
GT_CODE", myConnection)
typeDA.SelectCommand.CommandTimeout = 30
typeDA.Fill(typeDS, "General_Types")
I = 1
Do While IsDBNull(typeDS.Tables("General_Types").Rows(I)("GT_Image")) = True
I = I + 1
Loop
If IsDBNull(typeDS.Tables("General_Types").Rows(I)("GT_Image")) = False Then
Dim arrPicture() As Byte =
typeDS.Tables("General_Types").Rows(I)("GT_Image")
Dim ms As New MemoryStream(arrPicture)
With PictureBox3
..BorderStyle = BorderStyle.Fixed3D
..SizeMode = PictureBoxSizeMode.CenterImage
..Image = Image.FromStream(ms)
End With
Else
PictureBox3.Image = Nothing
End If
myConnection.Close()

On the local it's working fine and displaying the image.
On the server it's gaving me the error

An unhandled exception of type 'System.ArgumentException' occurred in
system.drawing.dll
Additional information: Invalid parameter used.

The line is
..Image = Image.FromStream(ms)

Any help will be appreciated.
Regards
Edward Koucherian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top