Image byte array

In the code below to load an image to a datarow i would like to understand why i need create a memory stream and then convert to byte array.
 Dim ms As System.IO.MemoryStream = New System.IO.MemoryStream
                PicLogotipo.Image.Save(ms, PicLogo.Image.RawFormat)
                datarow1("Logo") = ms.ToArray

Open in new window

rflorencioAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
CodeCruiserConnect With a Mentor Commented:
I think you may be able to get away with following

datarow1("Logo") = IO.File.ReadAllBytes("FilePath")
0
 
Éric MoreauSenior .Net ConsultantCommented:
what are you doing with the datarow/table? I have seen situation where it was the only way to provide image. My scenario was with Crystal Reports.
0
 
rflorencioAuthor Commented:
To save in database and retrieve to a picturebox.
0
 
Éric MoreauConnect With a Mentor Senior .Net ConsultantCommented:
an image is not something that can be saved into a database as is. You have to convert it to a Stream it first. This is exactly what this code is doing.
0
 
ArkCommented:
Internals
ReadAllBytes is implemented in an obvious way. It uses the using-statement on a FileStream. Then it loops through the file and puts the bytes into an array.
:)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.