home *** CD-ROM | disk | FTP | other *** search
Wrap
VERSION 5.00 Begin VB.Form frmCombine Appearance = 0 'Flat BackColor = &H80000005& Caption = "Combining Images" ClientHeight = 4200 ClientLeft = 1095 ClientTop = 1485 ClientWidth = 5790 BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H80000008& LinkTopic = "Form3" PaletteMode = 1 'UseZOrder ScaleHeight = 4200 ScaleWidth = 5790 Begin VB.PictureBox picSaved Appearance = 0 'Flat BackColor = &H80000005& ForeColor = &H80000008& Height = 510 Left = 420 ScaleHeight = 480 ScaleWidth = 480 TabIndex = 13 Top = 2760 Width = 510 End Begin VB.PictureBox picWork3 Appearance = 0 'Flat BackColor = &H80000005& ForeColor = &H80000008& Height = 510 Left = 3600 ScaleHeight = 480 ScaleWidth = 480 TabIndex = 11 Top = 3420 Width = 510 End Begin VB.PictureBox picWork2 Appearance = 0 'Flat BackColor = &H80000005& ForeColor = &H80000008& Height = 510 Left = 3600 ScaleHeight = 480 ScaleWidth = 480 TabIndex = 9 Top = 2820 Width = 510 End Begin VB.PictureBox picWork Appearance = 0 'Flat BackColor = &H80000005& ForeColor = &H80000008& Height = 510 Left = 3600 ScaleHeight = 480 ScaleWidth = 480 TabIndex = 8 Top = 2220 Width = 510 End Begin VB.PictureBox picCarMaskI Appearance = 0 'Flat AutoRedraw = -1 'True BackColor = &H80000005& ForeColor = &H80000008& Height = 510 Left = 3600 ScaleHeight = 480 ScaleWidth = 480 TabIndex = 3 Top = 1560 Width = 510 End Begin VB.PictureBox picCarMask Appearance = 0 'Flat AutoRedraw = -1 'True AutoSize = -1 'True BackColor = &H80000005& ForeColor = &H80000008& Height = 510 Left = 3600 Picture = "COMBINE.frx":0000 ScaleHeight = 480 ScaleWidth = 480 TabIndex = 2 Top = 960 Width = 510 End Begin VB.PictureBox picCar Appearance = 0 'Flat AutoSize = -1 'True BackColor = &H80000005& ForeColor = &H80000008& Height = 510 Left = 3600 Picture = "COMBINE.frx":0282 ScaleHeight = 480 ScaleWidth = 480 TabIndex = 1 Top = 360 Width = 510 End Begin VB.PictureBox picLeafs Appearance = 0 'Flat AutoSize = -1 'True BackColor = &H80000005& ForeColor = &H80000008& Height = 2280 Left = 420 MousePointer = 2 'Cross Picture = "COMBINE.frx":0504 ScaleHeight = 150 ScaleMode = 3 'Pixel ScaleWidth = 200 TabIndex = 0 Top = 360 Width = 3030 End Begin VB.Label Label7 Appearance = 0 'Flat BackColor = &H80000005& Caption = "Hold the original image segment to restore later." ForeColor = &H80000008& Height = 675 Left = 1080 TabIndex = 14 Top = 2760 Width = 1935 End Begin VB.Label Label6 Appearance = 0 'Flat BackColor = &H80000005& Caption = "Work area - step 3" ForeColor = &H80000008& Height = 435 Left = 4200 TabIndex = 12 Top = 3420 Width = 1275 End Begin VB.Label Label5 Appearance = 0 'Flat BackColor = &H80000005& Caption = "Work area - step 2" ForeColor = &H80000008& Height = 435 Left = 4200 TabIndex = 10 Top = 2820 Width = 1275 End Begin VB.Label Label4 Appearance = 0 'Flat BackColor = &H80000005& Caption = "Work area - step 1" ForeColor = &H80000008& Height = 375 Left = 4200 TabIndex = 7 Top = 2280 Width = 1395 End Begin VB.Label Label3 Appearance = 0 'Flat BackColor = &H80000005& Caption = "Inverted mask - created at runtime." ForeColor = &H80000008& Height = 615 Left = 4200 TabIndex = 6 Top = 1560 Width = 1395 End Begin VB.Label Label2 Appearance = 0 'Flat BackColor = &H80000005& Caption = "Mask to use." ForeColor = &H80000008& Height = 495 Left = 4200 TabIndex = 5 Top = 960 Width = 1395 End Begin VB.Label Label1 Appearance = 0 'Flat BackColor = &H80000005& Caption = "Picture to combine." ForeColor = &H80000008& Height = 495 Left = 4200 TabIndex = 4 Top = 360 Width = 1395 End Attribute VB_Name = "frmCombine" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False ' ------------------------------------------------------------------------ ' COMBINE.FRM ' Copyright (C) 1995-1997 Desaware ' You have a royalty-free right to use, modify, reproduce and distribute ' this file (and/or any modified version) in any way you find useful, ' provided that you agree that Desaware has no ' warranty, obligation or liability for its contents. ' ------------------------------------------------------------------------ Option Explicit ' Copyright 1997 by Desaware Inc. All Rights Reserved ' We use these variables to keep track of whether the ' car is currently merged, and if so, where. Dim CarIsMerged% Dim CarMergeLocX% Dim CarMergeLocY% Private Type RECT left As Long top As Long right As Long bottom As Long End Type Private Type POINTAPI x As Long y As Long End Type Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source Private Const SRCPAINT = &HEE0086 ' (DWORD) dest = source OR dest Private Const SRCAND = &H8800C6 ' (DWORD) dest = source AND dest Private Const SRCINVERT = &H660046 ' (DWORD) dest = source XOR dest Private Const SRCERASE = &H440328 ' (DWORD) dest = source AND (NOT dest ) Private Const NOTSRCCOPY = &H330008 ' (DWORD) dest = (NOT source) Private Const NOTSRCERASE = &H1100A6 ' (DWORD) dest = (NOT src) AND (NOT dest) Private Const MERGECOPY = &HC000CA ' (DWORD) dest = (source AND pattern) Private Const MERGEPAINT = &HBB0226 ' (DWORD) dest = (NOT source) OR dest Private Const PATCOPY = &HF00021 ' (DWORD) dest = pattern Private Const PATPAINT = &HFB0A09 ' (DWORD) dest = DPSnoo Private Const PATINVERT = &H5A0049 ' (DWORD) dest = pattern XOR dest Private Const DSTINVERT = &H550009 ' (DWORD) dest = (NOT dest) Private Const BLACKNESS = &H42& ' (DWORD) dest = BLACK Private Const WHITENESS = &HFF0062 ' (DWORD) dest = WHITE Private Declare Function BitBlt& Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) ' This routine combines the car into the leaf spread ' x and y are the start position for the merge in the leaf ' picture ' We'll use x = -1000 to indicate that the existing car ' location should be cleared. Private Sub CombineImage(x%, y%) Dim di% If CarIsMerged% Then ' Car is already merged - we had better remove ' it before merging it into the new location ' This is accomplished by simply restoring ' the saved area. di% = BitBlt(picLeafs.hDC, CarMergeLocX%, CarMergeLocY%, 32, 32, picSaved.hDC, 0, 0, SRCCOPY) CarIsMerged% = False End If If x% = -1000 Then Exit Sub ' Lets start by bringing in a portion of the leaf ' spread into the work picture. di% = BitBlt(picWork.hDC, 0, 0, 32, 32, picLeafs.hDC, x%, y%, SRCCOPY) ' We'll also hold the image in the saved area di% = BitBlt(picSaved.hDC, 0, 0, 32, 32, picLeafs.hDC, x%, y%, SRCCOPY) ' In a real application, we would perform all of the ' following operations on the same work picture. ' For illustrative purposes, we're using multiple ' pictures. ' Now lets Force to white the car area ' First bring over the current work area. di% = BitBlt(picWork2.hDC, 0, 0, 32, 32, picWork.hDC, 0, 0, SRCCOPY) ' Now OR in the inverted mask di% = BitBlt(picWork2.hDC, 0, 0, 32, 32, picCarMaskI.hDC, 0, 0, SRCPAINT) ' Now lets merge in the car ' First, bring over the current work area. di% = BitBlt(picWork3.hDC, 0, 0, 32, 32, picWork2.hDC, 0, 0, SRCCOPY) ' Now AND in the car picture di% = BitBlt(picWork3.hDC, 0, 0, 32, 32, picCar.hDC, 0, 0, SRCAND) ' And finally, Copy the bitmap back to the original spread di% = BitBlt(picLeafs.hDC, x%, y%, 32, 32, picWork3.hDC, 0, 0, SRCCOPY) ' Save the current status CarIsMerged% = True CarMergeLocX% = x% CarMergeLocY% = y% End Sub Private Sub Form_Load() Dim di% ' Note that in order for this BitBlt to work during ' form load, both of these picture controls must have ' autoredraw set to True - this assures that the ' device context refers to a real bitmap at all times. di% = BitBlt(picCarMaskI.hDC, 0, 0, 32, 32, picCarMask.hDC, 0, 0, SRCINVERT) End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single) CombineImage -1000, -1000 End Sub Private Sub picLeafs_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single) Dim usex%, usey% ' It's safe to use integers here, as we've set the ' scalemode to pixels. usex% = x usey% = y ' Rather than go through the hassle of partial bitmaps, ' we'll simply restrict the merge area to valid parts ' of the leaf picture control ' Important: We know that we're using a 32x32 pixel ' merge field. A robust version of this program would ' have to calculate the actual size of the merged image If usex% < 0 Then usex% = 0 If usey% < 0 Then usey% = 0 If usex% + 32 > picLeafs.ScaleWidth Then usex% = picLeafs.ScaleWidth - 32 If usey% + 32 > picLeafs.ScaleHeight Then usey% = picLeafs.ScaleHeight - 32 CombineImage usex%, usey% End Sub