By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,188 Members | 844 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,188 IT Pros & Developers. It's quick & easy.

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

P: 1
Expand|Select|Wrap|Line Numbers
  1.  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"
  2.         Dim imgMemoryStream As MemoryStream = New MemoryStream()
  3.         da = New OleDb.OleDbDataAdapter(sql, con)
  4.         da.Fill(ds, "RepairData")
  5.  
  6.         Dim c As Integer = ds.Tables("RepairData").Rows.Count
  7.         If c > 0 Then
  8.             Dim n As Integer
  9.             For n = 1 To c
  10.                 If ds.Tables("RepairData").Rows(n - 1)("signature") IsNot DBNull.Value Then
  11.                     Debug.WriteLine(ds.Tables("RepairData").Rows(n - 1)("signature"))
  12.                     Dim imageBytes() As Byte = _
  13.                         DirectCast(ds.Tables("RepairData").Rows(n - 1)("signature"), Byte())
  14.                     Dim myStream As New MemoryStream(imageBytes)
  15.                     ds.Tables("RepairData").Rows(n - 1)("signature") = Image.FromStream(myStream) 'error myStream here
  16.  
  17.                 End If
  18.             Next
  19.         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.FromStream (myStream) code.
Feb 16 '18 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 1,035
"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...
Feb 17 '18 #2

Frinavale
Expert Mod 5K+
P: 9,731
What are you trying to do on these lines?
Expand|Select|Wrap|Line Numbers
  1.  Dim myStream As New MemoryStream(imageBytes)
  2.                     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:
Expand|Select|Wrap|Line Numbers
  1. If ds.Tables("RepairData").Rows(n - 1)("signature") IsNot DBNull.Value Then
  2.   Debug.WriteLine(ds.Tables("RepairData").Rows(n - 1)("signature"))
  3.   Dim imageBytes() As Byte = DirectCast(ds.Tables("RepairData").Rows(n - 1)("signature"), Byte())
  4.  
  5.   Using ms As New IO.MemoryStream(imageBytes)
  6.     Dim imageFromStream As Drawing.Image = Drawing.Image.FromStream(ms)
  7.     'Use the image appropriately  
  8.   End Using
  9. End If
  10.  
Feb 21 '18 #3

Post your reply

Sign in to post your reply or Sign up for a free account.