question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Load image from Stream

See original GitHub issue

Magick.NET-Q16-AnyCPU v7.11.1

I load from net image and try create “MagickImage”, but i catch next error:

using (var httpResponseStream = await httpResponse.Content.ReadAsStreamAsync())
{
    using (var image = new MagickImage(httpResponseStream))
    {
        var size = new MagickGeometry(width, height);
        image.Resize(size);
        image.Format = MagickFormat.Jpg;
        image.Write(outStream);
     }
}
ImageMagick.MagickCoderErrorException: TIFF directory is missing required "ImageLength" field. `MissingRequired' @ error/tiff.c/TIFFErrors/656
   at ImageMagick.NativeInstance.CheckException(IntPtr exception, IntPtr result)
   at ImageMagick.MagickImage.NativeMagickImage.ReadStream(MagickSettings settings, ReadWriteStreamDelegate reader, SeekStreamDelegate seeker, TellStreamDelegate teller)
   at ImageMagick.MagickImage.Read(Stream stream, MagickReadSettings readSettings, Boolean ping)

If I load “MagickImage” from a file then there is no such error:

using (var image = new MagickImage(path))
{
    var size = new MagickGeometry(width, height);
    image.Resize(size);
    image.Format = MagickFormat.Jpg;
    image.Write($"{path}_{image.Width}x{image.Height}.jpg");
}

I split file on part, please remove “zip” in the end.

sony_a7_iii_01.001.zip sony_a7_iii_01.002.zip sony_a7_iii_01.003.zip sony_a7_iii_01.004.zip

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
dlemstracommented, Apr 11, 2019

ImageMagick will try to guess the file format because you are reading from a stream and guesses that your file is a TIFF file. When reading from file it sees the .arw extension and knows your file is a RAW file. If you want to read from a stream you will need to tell Magick.NET the format of the file:

var settings = new MagickReadSettings { Format = MagickFormat.Raw };
using (var image = new MagickImage(stream, settings))
{
}
0reactions
tttrrryyyyeercommented, Apr 15, 2019

@dlemstra thank you, it works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Image.FromStream Method (System.Drawing)
Creates an Image from the specified data stream, optionally using embedded color management information and validating the image data.
Read more >
c# - How to convert System.IO.Stream into an Image?
Bitmap image = new Bitmap(streamF); ConsoleWriteImage(image); //REMEMBER = in console App you must use < using System.Drawing; > //to handle ...
Read more >
Load Image | Documents for Imaging .NET Edition
To load an image from stream, instantiate the FileStream class to read the image in the stream and load the file in GcBitmap...
Read more >
Load Image from Stream
To load an image from a memory or file stream, use the ImageX.FromStream methods. When called, the FromStream methods store a copy of...
Read more >
Image.FromStream: load image from stream - C# / C Sharp
4. Clone Image ; 5. Get Image Resolution and Image size and Display size ; 6. Draw image based on its size ;...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found