Solved

Image byte array

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

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 69

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 27

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sign PDF document with digital PFX file from VB.NET 2010 1 29
Round a string to two digits 12 31
Getfiles in vb.net 28 43
Saveas need to save a copy 16 26
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now