1

I'm using the following code to create single tiff file from a list of images using MagickImage.NET Library:

    /// <summary>
    /// Create single tiff file from a list of base64String images
    /// </summary>
    /// <param name="pages">A list of base64String images</param>
    /// <returns>Byte array of the created tiff file</returns>
    public static byte[] CreateSingleTiff(List<string> pages)
    {
        MagickImage pageImage;
        using (MemoryStream byteStream = new MemoryStream())
        {
            using (MagickImageCollection imagecoll = new MagickImageCollection())
            {

                for (int i = 0; i < pages.Count; i++)
                {
                    byte[] newBytes = Convert.FromBase64String(pages[i].Replace("data:image/Jpeg;base64,", ""));
                    pageImage = new MagickImage(newBytes);
                    imagecoll.Add(pageImage);
                }
                return imagecoll.ToByteArray();//The problem occurs right here
            }
        }
    }

But I'm getting the first page only!.

Here is the line I used to write the image on disk:

Image.FromStream(new MemoryStream(result)).Save(path, System.Drawing.Imaging.ImageFormat.Tiff);

I tried to dig stackoverflow for something similar but I had no luck. Apparently there is no good support for MagickImage.NET Library. If you see this method is useless what are the other available methods beside this and this one

Community
  • 1
  • 1
Ibrahim Amer
  • 1,147
  • 4
  • 19
  • 46

1 Answers1

0

It seems like there is a problem with this line return imagecoll.ToByteArray();, the image is a multipage tiff image and the length of the byte array returned is too small compared with the images being added to the tiff image. I found an overloaded method which takes image format as a parameter using MagickFormat enum, in my case I usedMagickFormat.Tiff.

Ibrahim Amer
  • 1,147
  • 4
  • 19
  • 46
  • When you don't specify the format it will use the format of the original image which is JPEG and that format does not support multiple layers. That is why you only get the first image. (p.s. you can directly write the byte array to disk) – dlemstra Nov 20 '16 at 12:41