Create Bitmap, Size, and Combine example for Visual Basic

This example creates a bitmap for Raster2 (same size and BPS as LEADRasterView1.Raster) and fills it with green. It resizes the LEADRasterView1.Raster bitmap, then uses a loop to do multiple combines with the Raster2 bitmap. It then copies the Raster2 bitmap to LEADRasterView1 and redisplays LEADRasterView1.

Dim Factory As New LEADRasterFactory
Dim Raster2 As LEADRaster
Dim szLic As String
Dim RasterProc As New LEADRasterProcess
Dim MyWidth As Single
Dim MyHeight As Single
Dim MyBPS As Integer
Dim ImageWidth As Integer
Dim ImageHeight As Integer
Dim TestWidth As Integer
Dim TestHeight As Integer
Dim VFactor As Integer
Dim VSpacing As Integer
Dim HFactor As Integer
Dim HSpacing As Integer
Dim DstT As Single
Dim DstL As Single
Dim SrcL As Single
Dim SrcT As Single
Dim DstW As Single
Dim DstH As Single
Dim MyOP As CombineConstants

MousePointer = 11 ' hourglass

'Create a new ILEADRaster Object
szLic = "LEADTOOLS OCX Copyright (c) 1991-2005 LEAD Technologies, Inc." & vbCrLf & vbCrLf
Set Raster2 = Factory.CreateObject("LEADRaster.LEADRaster", szLic)

' Create the Raster2 bitmap.
MyWidth = LEADRasterView1.Raster.BitmapWidth
MyHeight = LEADRasterView1.Raster.BitmapHeight
MyBPS = LEADRasterView1.Raster.BitmapBits
Raster2.CreateBitmap MyWidth, MyHeight, MyBPS
RasterProc.Fill Raster2, RGB(0, 255, 0) ' fill with green
' Resize the LEADRasterView1 bitmap
ImageWidth = CInt(MyWidth * 0.3)
ImageHeight = CInt(MyHeight * 0.3)
RasterProc.Size LEADRasterView1.Raster, ImageWidth, ImageHeight, RESIZE_RESAMPLE
' Initialize the variables used for multiple combines.
TestWidth = MyWidth ' Used for horizontal positioning
TestHeight = MyHeight ' Used for vertical positioning
VFactor = Int(MyHeight / ImageHeight) + 1 ' Number spaces between images
VSpacing = CInt((MyHeight Mod ImageHeight) / VFactor) ' Pixels between images
HFactor = Int(MyWidth / ImageWidth) + 1 ' Number spaces between images
HSpacing = CInt((MyWidth Mod ImageWidth) / HFactor) ' Pixels between images
DstT = VSpacing ' Top coordinate of the destination rectangle
SrcL = 0 ' Left coordinate of the source rectangle
SrcT = 0 ' Top coordinate of the source rectangle
DstW = ImageWidth  ' Width of the destination rectangle
DstH = ImageHeight ' Height of the destination rectangle
MyOP = CB_OP_ADD + CB_DST_0 ' Operation flags used when combining images
' Do the loop that does the multiple combines
While TestHeight > ImageHeight ' Vertical loop
    DstT = MyHeight - TestHeight + VSpacing
    TestHeight = TestHeight - ImageHeight - VSpacing
    While TestWidth > ImageWidth 'Horizontal loop
        DstL = MyWidth - TestWidth + HSpacing
        TestWidth = TestWidth - ImageWidth - HSpacing
        RasterProc.Combine Raster2, DstL, DstT, DstW, DstH, LEADRasterView1.Raster, SrcL, SrcT, MyOP
    Wend
    TestWidth = MyWidth
Wend
' Copy the Raster2 bitmap to LEADRasterView1
LEADRasterView1.Raster.Bitmap = Raster2.Bitmap
'Set the image display size to match the LEADRasterView control
LEADRasterView1.SetDstRect 0, 0, LEADRasterView1.ScaleWidth, LEADRasterView1.ScaleHeight
LEADRasterView1.SetDstClipRect 0, 0, LEADRasterView1.ScaleWidth, LEADRasterView1.ScaleHeight
LEADRasterView1.ForceRepaint ' Repaint the image
MousePointer = 0 ' default