Esempio n. 1
0
        private static byte[] GeneratePngOutput(byte[] renderedBytes, out string mimeType)
        {
            Bitmap        tiff  = (Bitmap)Image.FromStream(new MemoryStream(renderedBytes));
            List <Bitmap> pages = ImageHelpers.GetAllPages(tiff).Select(p => (Bitmap)p).ToList();

            var mergedBitmap = new Bitmap(pages.Max(p => p.Width), pages.Sum(p => p.Height));

            int heigthShift = 0;

            foreach (var image in pages)
            {
                for (int x = 0; x < image.Width; x++)
                {
                    for (int y = 0; y < image.Height; y++)
                    {
                        mergedBitmap.SetPixel(x, y + heigthShift, image.GetPixel(x, y));
                    }
                }

                heigthShift += image.Height;
            }

            var pngStream = new MemoryStream();

            mergedBitmap.Save(pngStream, ImageFormat.Png);
            pngStream.Seek(0, 0);

            mimeType = "image/png";

            return(pngStream.ToArray());
        }