MakeTiff.cs
//
// This code is part of GrapeCity Documents for Imaging samples.
// Copyright (c) GrapeCity, Inc. All rights reserved.
//
using System;
using System.IO;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using GrapeCity.Documents.Drawing;
using GrapeCity.Documents.Text;
using GrapeCity.Documents.Imaging;

namespace GcImagingWeb.Samples
{
    // This sample loads several JPEG images and combines them
    // into a single multi-frame TIFF.
    public class MakeTiff
    {
        public Stream GenerateImageStream(ImageEncoding targetEncoding, int pixelWidth = 1024, int pixelHeight = 1024, bool opaque = true, float dpiX = 96, float dpiY = 96)
        {
            if (targetEncoding != ImageEncoding.Tiff)
                throw new Exception("This sample only supports TIFF output format.");

            var sources = new string[]
            {
                Path.Combine("Resources", "Images", "colosseum.jpg"),
                Path.Combine("Resources", "Images", "lady.jpg"),
                Path.Combine("Resources", "Images", "minerva.jpg"),
                Path.Combine("Resources", "Images", "rome.jpg"),
            };

            var ms = new MemoryStream();
            using (var tw = new GcTiffWriter(ms))
            {
                foreach (var src in sources)
                    using (var bmp = new GcBitmap(src))
                        tw.AppendFrame(bmp);
            }
            ms.Seek(0, SeekOrigin.Begin);
            return ms;
        }

        public ImageEncoding DefaultEncoding { get => ImageEncoding.Tiff; }
    }
}