ReadIco.vb
'' 
'' このコードは、DioDocs for Imaging のサンプルの一部として提供されています。
'' © MESCIUS inc. All rights reserved.
'' 
Imports System
Imports System.IO
Imports System.Drawing
Imports System.Linq
Imports GrapeCity.Documents.Drawing
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Imaging

'' このサンプルは、MakeIco サンプルで生成された .ICO を読み込み、
'' その中に含まれるすべてのフレームを、
'' 生成される画像の対角線上に沿って描画します。
Public Class ReadIco
    Public Function GenerateImage(
            ByVal pixelSize As Size,
            ByVal dpi As Single,
            ByVal opaque As Boolean,
            Optional ByVal sampleParams As String() = Nothing) As GcBitmap

        Dim x As Integer = 0, y As Integer = 0

        Dim srcPath = Path.Combine("Resources", "ImagesBis", "mescius-logomark-c.ico")
        Using bmp As New GcBitmap()
            Using ico As New GcIco(srcPath)
                Dim w = ico.Frames.Sum(Function(f) f.Width)
                Dim h = ico.Frames.Sum(Function(f) f.Height)
                bmp.CreateImage(w, h, False)
                bmp.Clear()
                For i As Integer = 0 To ico.Frames.Count - 1
                    Using tbmp = ico.Frames(i).ToGcBitmap()
                        bmp.BitBlt(tbmp, x, y)
                        x += tbmp.PixelWidth
                        y += tbmp.PixelHeight
                    End Using
                Next
                Return bmp.Clip(New Rectangle(0, 0, x, y))
            End Using
        End Using
    End Function
End Class