I have var image = ImageFile.FromFile(pathToImage);
Can an Extension ToByteArray() on ImageFile be easily implemented as shown below? I can easily implement from IO Stream but since the file is already open for getting Exif metadata, I am trying to avoid opening for getting IO Stream.
An alternative question is can ImageFile be converted to MemoryStream which allows me to get to a byte array?
Apologies as I am new to ImageFile.
byte[] imageData = image.ToByteArray();
public static class MyExtensions
{
public static byte[] ToByteArray (this ImageFile imageFile)
{
var memoryStream = <## Get MemoryStream from imageFile ##>
return memoryStream.ToArray();
}
}
UPDATE after a few hours:
I think I figured out?? but someone correct me if wrong;
public static byte[] ToByteArray (this ImageFile imageFile)
{
MemoryStream memStream = new MemoryStream();
imageFile.Save(memStream );
return memStream.ToArray();
}
I have
var image = ImageFile.FromFile(pathToImage);
Can an Extension
ToByteArray()
on ImageFile be easily implemented as shown below? I can easily implement from IOStream
but since the file is already open for getting Exif metadata, I am trying to avoid opening for getting IOStream
.An alternative question is can
ImageFile
be converted toMemoryStream
which allows me to get to a byte array? Apologies as I am new toImageFile
.byte[] imageData = image.ToByteArray();
UPDATE after a few hours:
I think I figured out?? but someone correct me if wrong;