ReadIco.vb
''
'' This code is part of Document Solutions for Imaging demos.
'' Copyright (c) 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

'' This sample loads the .ICO generated by the MakeIco sample,
'' and renders all frames found in it along the diagonal of the
'' resulting image.
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