convert a byte array to an image that will display in a PictureBox on a VB form data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jannis71retired
    New Member
    • Feb 2018
    • 1

    convert a byte array to an image that will display in a PictureBox on a VB form data

    Code:
     sql = "SELECT  RecordNum, DelDate, FName, Lname, Phone, Email, DevMake, DevModel, Carrier, DevColor, UsserPassword, MobileId, Repaired, RepComments, ServiceType, FindUs, DateDone, AuthorizeRepair, BackUpInfo, TecTrained, NotResponsible, VoidWarranty, FeesPaid, DiagnosticFee, Pricequote, Deposit, Total, signature  FROM RepairData ORDER BY Lname"
            Dim imgMemoryStream As MemoryStream = New MemoryStream()
            da = New OleDb.OleDbDataAdapter(sql, con)
            da.Fill(ds, "RepairData")
    
            Dim c As Integer = ds.Tables("RepairData").Rows.Count
            If c > 0 Then
                Dim n As Integer
                For n = 1 To c
                    If ds.Tables("RepairData").Rows(n - 1)("signature") IsNot DBNull.Value Then
                        Debug.WriteLine(ds.Tables("RepairData").Rows(n - 1)("signature"))
                        Dim imageBytes() As Byte = _
                            DirectCast(ds.Tables("RepairData").Rows(n - 1)("signature"), Byte())
                        Dim myStream As New MemoryStream(imageBytes)
                        ds.Tables("RepairData").Rows(n - 1)("signature") = Image.FromStream(myStream) 'error myStream here
    
                    End If
                Next
            End If
    Using the above code. I have found it on the internet in several places but I get an invalid parameter error for myStream variable in the Image.FromStrea m (myStream) code.
    Last edited by Frinavale; Feb 21 '18, 03:56 PM.
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    "Image" is not declared in the piece of code you have copied here. that is making it hard to guess which parameters are missing.

    Also bytes.com provides a '[CODE/]' button for copying/pasting pieces of code in a message...

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      What are you trying to do on these lines?
      Code:
       Dim myStream As New MemoryStream(imageBytes)
                          ds.Tables("RepairData").Rows(n - 1)("signature") = Image.FromStream(myStream) 'error myStream here
      Are you attempting to set the "signature" column for the row in the data table to a Stream?????

      Why?

      Shouldn't you be creating a new image and then applying it where needed?

      For example:
      Code:
      If ds.Tables("RepairData").Rows(n - 1)("signature") IsNot DBNull.Value Then
        Debug.WriteLine(ds.Tables("RepairData").Rows(n - 1)("signature"))
        Dim imageBytes() As Byte = DirectCast(ds.Tables("RepairData").Rows(n - 1)("signature"), Byte())
            
        Using ms As New IO.MemoryStream(imageBytes)
          Dim imageFromStream As Drawing.Image = Drawing.Image.FromStream(ms)
          'Use the image appropriately  
        End Using
      End If

      Comment

      Working...