I'm already using ORacle 11G . The problem is when i'm using System.Data.Oracleclient to pull blob into picturebox it's ok, but when i'm using OracleDataaccess.Client / Types.....there no image appear n comeout error " Parameter is not valid" in this coding :-

Quoted Text Here

Dim bmp As Bitmap = Image.FromStream(ms)

can anyone help me....Tq

4 Years
Discussion Span
Last Post by kerek2
Dim stream As New MemoryStream(imagedata)
                    stream.Write(imagedata, 0, imagedata.Length)
                      Dim bmp As Bitmap = Image.FromStream(stream) - Got Parameter is Invalid
                       Dim bmp As New Bitmap(stream)

Please guide me...tq

 If Not oradr.Item("PICTURE").Equals(DBNull.Value) Then

                    ' Get the image from the database.
                    Dim imagedata() As Byte = CType(oradr.Item("PICTURE"), Byte())

                    'read the image as a stream and make a bitmap out of it
                    Dim stream As New MemoryStream(imagedata)
                    Dim bmp As New Bitmap(stream)

                    ' Resize Image Before Uploading to DataBase
                    Dim imageToBeResized As System.Drawing.Image = (bmp)
                    Dim imageHeight As Integer = imageToBeResized.Height
                    Dim imageWidth As Integer = imageToBeResized.Width
                    Dim maxHeight As Integer = 246
                    Dim maxWidth As Integer = 184
                    imageHeight = maxHeight
                    imageWidth = maxWidth

                    'DECLARE IMAGE NEW RESIZE
                    Dim bmpnew As New Bitmap(imageToBeResized, imageWidth, imageHeight)
                    Dim img = New Bitmap(bmpnew)

                    'STREAM BACK IMAGE & SAVE INTO JPEG
                    Dim ms As New MemoryStream()
                    img.Save(ms, Imaging.ImageFormat.Jpeg)
                    Dim imgData(ms.Length - 1) As Byte
                    ms.Position = 0
                    ms.Read(imgData, 0, ms.Length)
                    Dim fs As FileStream = New FileStream("PHOTO\STAFF\" & oradr.Item("ID") & ".jpg", FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read)
                    fs.Write(imgData, 0, UBound(imgData))

end if

When i'm using System.Data.OracleClient, it's working but when i'm switch to Oracle.Dataaccess.Client/types, error "Parameter is Not Valid" appear at -" Dim bmp As New Bitmap(stream)"...pleas help me


It appears that you are trying to convert the reader item directly into a byte array. Everything I've seen on using the Oracle library uses the OracleBlob type to extract the data. The following demonstrates the code pattern.

Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types

Public Class Form1

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

      Dim cn As New OracleConnection("your connection string")

      Dim cmd As New OracleCommand("Select Pk, Pic From PicTable Where PK=Something", cn)
      Dim rdr As OracleDataReader = cmd.ExecuteReader
      Dim RecordFound As Boolean = rdr.Read
      'Item 1 is the pic item
      If RecordFound AndAlso rdr.Item(1) IsNot Nothing Then

         Dim blob As OracleBlob = rdr.GetOracleBlob(1)
         Dim blobbytes(CInt(blob.Length)) As Byte
         blob.Read(blobbytes, 0, CInt(blob.Length))
         'create a new memory stream initialized with blobbytes
         Dim ms As New IO.MemoryStream(blobbytes)
         Dim pic As Image = Image.FromStream(ms)
      End If

   End Sub
End Class
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.