Solved

Image byte array

Posted on 2014-01-03
5
367 Views
Last Modified: 2014-02-11
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

0
Comment
Question by:rflorencio
5 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 39753465
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
 

Author Comment

by:rflorencio
ID: 39753511
To save in database and retrieve to a picturebox.
0
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 100 total points
ID: 39753609
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
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 400 total points
ID: 39754896
I think you may be able to get away with following

datarow1("Logo") = IO.File.ReadAllBytes("FilePath")
0
 
LVL 28

Expert Comment

by:Ark
ID: 39781211
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 Populate DataModel with DataTable 44 38
Help with exporting to excel 4 36
Sql server, import complete table, using vb.net 9 43
get combo value in class 5 14
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question