olminkow
olminkow

Reputation: 121

Having issues reading a image file and putting it into a byte array

So I am working within DbContext.SeedData.cs

I'm returning a method back with appropriate information such as names, id, description. Those work. I am trying to, while within the DbContext.SeedData.cs, read an image file and assign it into a new byte array.

Image = new byte[]{ FileStream(image, FileMode.Open, FileAccess.Read).Length }

The error I keep getting is: Non-invocable member 'FileStream' cannot be used like a method.

How do I use FileStream in the proper context to read the image and convert it into byte code?

Upvotes: 1

Views: 609

Answers (2)

T McKeown
T McKeown

Reputation: 12847

You need to either read all the bytes via:

var fs = new FileStream(image, FileMode.Open, FileAccess.Read);

Image = new byte[fs.Length];

fs.Read( Image, 0 , fs.Length);

or use

Image = System.IO.File.ReadAllBytes(image);

Upvotes: 1

Robert McKee
Robert McKee

Reputation: 21487

Just use:

Image = System.IO.File.ReadAllBytes(image);

Upvotes: 1

Related Questions