ReadIco.cs
// 
// このコードは、DioDocs for Imaging のサンプルの一部として提供されています。
// © MESCIUS 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 DsImagingWeb.Demos
{
    // このサンプルは、MakeIco サンプルで生成された .ICO を読み込み、
    // その中に含まれるすべてのフレームを、
    // 生成される画像の対角線上に沿って描画します。
    public class ReadIco
    {
        public GcBitmap GenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null)
        {
            int x = 0, y = 0;

            var srcPath = Path.Combine("Resources", "ImagesBis", "mescius-logomark-c.ico");
            using (var bmp = new GcBitmap())
            using (var ico = new GcIco(srcPath))
            {
                var w = ico.Frames.Sum(f_ => f_.Width);
                var h = ico.Frames.Sum(f_ => f_.Height);
                bmp.CreateImage(w, h, false);
                bmp.Clear();
                for (int i = 0; i < ico.Frames.Count; ++i)
                {
                    using (var tbmp = ico.Frames[i].ToGcBitmap())
                    {
                        bmp.BitBlt(tbmp, x, y);
                        x += tbmp.PixelWidth;
                        y += tbmp.PixelHeight;
                    }
                }
                return bmp.Clip(new Rectangle(0, 0, x, y));
            }
        }
    }
}