Solved

Image byte array

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 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

14 Experts available now in Live!

Get 1:1 Help Now