BmpTransforms.vb
''
'' This code is part of Document Solutions for Imaging demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.IO
Imports System.Drawing
Imports System.Numerics
Imports GrapeCity.Documents.Drawing
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Imaging

'' This sample demonstrates how to use bitmap transformations
'' such as resizing, flipping and rotating.
Public Class Transforms
    Function GenerateImage(
        ByVal pixelSize As Size,
        ByVal dpi As Single,
        ByVal opaque As Boolean,
        Optional ByVal sampleParams As String() = Nothing) As GcBitmap

        Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi)
        bmp.Clear(Color.Transparent)

        Dim side = pixelSize.Width / 2
        Dim side2 = side / 2
        Dim bmpLarge, bmpFlip, bmpSmall1, bmpSmall2, bmpSmall3, bmpSmall4
        Using bmpSrc = New GcBitmap(Path.Combine("Resources", "Stock", "goldfish.jpg"))
            bmpSrc.Opaque = opaque
            bmpLarge = bmpSrc.Resize(side, side)
            bmpFlip = bmpLarge.FlipRotate(FlipRotateAction.FlipHorizontal)
            bmpSmall1 = bmpSrc.Resize(side2, side2)
            bmpSmall2 = bmpSmall1.FlipRotate(FlipRotateAction.Rotate270)
            bmpSmall3 = bmpSmall1.FlipRotate(FlipRotateAction.FlipVertical)
            bmpSmall4 = bmpSmall1.FlipRotate(FlipRotateAction.Rotate90)
        End Using

        bmp.BitBlt(bmpLarge, 0, 0)
        bmp.BitBlt(bmpFlip, pixelSize.Width - bmpFlip.Width, 0)
        bmp.BitBlt(bmpSmall1, 0, side + side2 / 2)
        bmp.BitBlt(bmpSmall2, side2, side + side2 / 2)
        bmp.BitBlt(bmpSmall3, side2 * 2, side + side2 / 2)
        bmp.BitBlt(bmpSmall4, side2 * 3, side + side2 / 2)

        '' Dispose bitmaps except the resulting one
        bmpLarge.Dispose()
        bmpFlip.Dispose()
        bmpSmall1.Dispose()
        bmpSmall2.Dispose()
        bmpSmall3.Dispose()
        bmpSmall4.Dispose()

        Return bmp
    End Function
End Class