Hi,

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

Recommended Answers

All 7 Replies

Can you please post a larger snippet of the code?

Where is the memory stream being declared?

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)
                    stream.Close()

Please guide me...tq

could you also show the code where you retrieve the blob and fill imagedata?

 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)
                    stream.Close()

                    ' 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))
                    fs.Close()

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")
      cn.Open()

      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)
         ms.Close()
      End If
      cn.Close()

   End Sub
End Class

Thanks...i will try it...

no success......error n can't run...please help me

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.