Skip to content

Decoding failes with memory stream at EOF #72

@corradolab

Description

@corradolab

Hi,
decoding from a memory stream fails if the stream position is already at EOF.
In example:

Stream zipStream = ... // get a zipped jpeg
MemoryStream unzippedStream = new MemoryStream();
await zipStream.CopyToAsync(unzippedStream);
Image image = new Image(unzippedStream); 

Code above fails with a NotSupportedException "Image cannot be loaded. Available formats: ..." because Image.Decode() find an empty header (Image{TColor].cs line 447) calling stream.Read() at EOF.

The following works:

Stream zipStream = ... // get a zipped jpeg
MemoryStream unzippedStream = new MemoryStream();
await zipStream.CopyToAsync(unzippedStream); 

unzippedStream.Position = 0;  // add this to reset stream position

Image image = new Image(unzippedStream); 

I think Image constructor should set Stream.Position = 0 when decoding images from streams.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions