Available in the LEADTOOLS Imaging toolkit. |
Create Bitmap, Size, and Combine example for Visual Basic
This example creates a bitmap for Lead2 (same size and BPS as Lead 1) and fills it with green. It resizes the Lead1 bitmap, then uses a loop to do multiple combines with the Lead2 bitmap. It then copies the Lead2 bitmap to Lead1 and redisplays Lead1.
MousePointer = 11 ' hourglass
' Create the Lead2 bitmap. (The control must already be on the form).
MyWidth = Lead1.BitmapWidth
MyHeight = Lead1.BitmapHeight
MyBPS = Lead1.BitmapBits
Lead2.CreateBitmap MyWidth, MyHeight, MyBPS
Lead2.Fill RGB(0, 255, 0) ' fill with green
' Resize the Lead1 bitmap
ImageWidth = CInt(MyWidth * 0.3)
ImageHeight = CInt(MyHeight * 0.3)
Lead1.Size 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
Lead2.Combine DstL, DstT, DstW, DstH, Lead1.Bitmap, SrcL, SrcT, MyOp
Wend
TestWidth = MyWidth
Wend
' Copy the Lead2 bitmap to Lead1
Lead1.Bitmap = Lead2.Bitmap
'Set the image display size to match the LEAD control
Lead1.SetDstRect 0, 0, Lead1.ScaleWidth, Lead1.ScaleHeight
Lead1.SetDstClipRect 0, 0, Lead1.ScaleWidth, Lead1.ScaleHeight
Lead1.ForceRepaint ' Repaint the image
MousePointer = 0 ' default