Solved

Image byte array

Posted on 2014-01-03
5
371 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

679 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