BmpTransforms.vb
''
'' This code is part of GrapeCity Documents for Imaging samples.
'' Copyright (c) GrapeCity, 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(
            Optional pixelWidth As Integer = 1024,
            Optional pixelHeight As Integer = 1024,
            Optional opaque As Boolean = True,
            Optional dpiX As Single = 96,
            Optional dpiY As Single = 96) As GcBitmap
        Dim bmp = New GcBitmap(pixelWidth, pixelHeight, opaque, dpiX, dpiY)
        bmp.Clear(Color.Transparent)

        Dim side = pixelWidth / 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, pixelWidth - 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