Quantcast
Channel: magick Discussions Rss Feed
Viewing all articles
Browse latest Browse all 3693

New Post: Error Reading Pages as PNGs with Byte Arrays

$
0
0
Hello again,

I'm trying to initialize an image collection with the .Read overload using a byte array and settings object. The Format property is set to MagickFormat.Png. This works fine when I use the FileInfo overload. However, if I try to read the file and pass in the byte array, it throws the following:

ImproperImageHeader @ error/png.c/ReadPNGImage/3973 magick.net

Here's my method:
internal static IEnumerable<string> GetDocumentImagesAsBase64(byte[] documentBytes)
{
    MagickReadSettings magickSettings;
    InitializeSettings(MagickFormat.Png, out magickSettings);
            
    List<string> strings = new List<string>();
            
    using (var imageCollection = new MagickImageCollection())
    {
        imageCollection.Read(documentBytes, magickSettings);

        if (imageCollection.Count <= 0) return null;

        strings.AddRange(imageCollection.Select(magickImage => magickImage.ToBase64()));
    }

    return strings;
}

private static void InitializeSettings(MagickFormat format, out MagickReadSettings magickSettings)
{
    const double imageOutputDpi = (double)150;

    magickSettings = new MagickReadSettings
    {
        Density = new PointD(imageOutputDpi, imageOutputDpi),
        Format = format,
        ColorSpace = ColorSpace.GRAY
    };
}
A quick Google lead me here: http://stackoverflow.com/questions/8109536/imagemagick-not-working-with-png-files

This has me curious if the internal ImageMagick libraries have been built with the stated options as noted in that URL, granted it talks about Ruby. Though, why it works with a file reference but not with a byte array is puzzling to me. Is there anything you can suggest?

Viewing all articles
Browse latest Browse all 3693

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>