picturebox:Source --->picture:Dest
Cancel = False
StartLineArt.Enabled = False
StartEdgeDetect.Enabled = False
Dim Col As Long ' hold the colour of the pixel minus the colour of the pixel next to it
Dim Total As Long
Total = (Source.Width / Screen.TwipsPerPixelX) * (Source.Height / Screen.TwipsPerPixelY)
Dest.Cls
For x = 1 To Source.Width \ Screen.TwipsPerPixelX 'loop through the x-pixels
For y = 1 To Source.Height \ Screen.TwipsPerPixelY 'loop through the y-pixels
Col = Abs(GetPixel(Source.hdc, x, y) - GetPixel(Source.hdc, x, y - 1)) ' hold the colour of the pixel minus the colour of the pixel on the top of it
If Col > (Tolerance.Value) ^ 3 Then Col = vbWhite Else Col = 0 ' choose if the colour is of high contrast
If Invert.Value = 0 Then Col = (vbWhite - Col) ' check for an invert
If Col = 0 Then SetPixel Dest.hdc, x, y, Col ' plot pixel
Col = Abs(GetPixel(Source.hdc, x, y) - GetPixel(Source.hdc, x - 1, y)) ' hold the colour of the pixel minus the colour of the pixel on the left of it
If Col > (Tolerance.Value) ^ 3 Then Col = vbWhite Else Col = 0 ' choose if the colour is of high contrast
If Invert.Value = 0 Then Col = (vbWhite - Col) ' check for an invert
If Col = 0 Then SetPixel Dest.hdc, x, y, Col ' plot pixel
Next y 'loop through the y-pixels
PercentDone.Caption = Int(((x * y) / Total) * 100) & "%" 'calculate the percent done.
Dest.Refresh
DoEvents
If Cancel = True Then GoTo Finish:
Next x 'loop through the x-pixels
Finish:
StartLineArt.Enabled = True
StartEdgeDetect.Enabled = True
Public Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Public Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Public Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Public Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Public Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Public Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As Any, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Public Const RGN_OR = 2
Public Const ALTERNATE = 1 ' ALTERNATE and WINDING are
Public Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Public Type POINTAPI
X As Long
Y As Long
End Type
Public Sub SetAutoRgn(hForm As Form, hbm As Long, Optional transColor As Byte = vbNull)
Dim X As Long, Y As Long
Dim Rgn1 As Long, Rgn2 As Long
Dim SPos As Long, Epos As Long, SPos1 As Long, Epos1 As Long
Dim bm As BITMAP
'Dim hbm As Long
Dim Wid As Long, hGt As Long
Dim Bind As Boolean
Dim bmByte() As Byte
Dim Pt(0 To 3) As POINTAPI
Bind = False
' »ñÈ¡´°Ìå±³¾°Í¼Æ¬³ß´ç
'hbm = hForm.Pic
If hbm = 0 Then Exit Sub
GetObject hbm, Len(bm), bm
Wid = bm.bmWidth
hGt = bm.bmHeight
'¸Ä±ä´°Ìå³ß´çÒÔ·ûºÏ±³¾°Í¼Æ¬´óС
hForm.Height = hGt * Screen.TwipsPerPixelY
hForm.Width = Wid * Screen.TwipsPerPixelX
' Rgn1 = CreateRectRgn(0, 0, hGt, Wid)
' SetWindowRgn hForm.hWnd, Rgn1, True
ReDim bmByte(1 To bm.bmWidthBytes, 1 To hGt)
SetWindowRgn hForm.hWnd, Rgn1, True
GetBitmapBits hbm, bm.bmWidthBytes * hGt, bmByte(1, 1) '»ñȡͼÏñÊý×é
'Èç¹ûûÓд«Èë transColor ²ÎÊý,ÔòÓõÚÒ»¸öÏñËØ×÷Ϊ͸Ã÷É«
If transColor = vbNull Then transColor = bmByte(1, 1)
Rgn1 = CreateRectRgn(0, 0, 0, 0)
For Y = 1 To hGt 'ÖðÐÐɨÃè
X = 0
Do
X = X + 1
While (bmByte(X, Y) = transColor) And (X < Wid) '((bmByte(X, Y) >= transColor - 2) And (bmByte(X, Y) <= transColor + 2)) And (X < Wid)
X = X + 1 'Ìø¹ý͸Ã÷É«µÄµã
Wend
If X < Wid Then
SPos = X
While (bmByte(X, Y) <> transColor) And (X < Wid) '((bmByte(X, Y) <= transColor - 2) Or (bmByte(X, Y) >= transColor + 2)) And (X < Wid)
X = X + 1 'Ìø¹ý²»Í¸Ã÷µÄµã
Wend
Epos = X - 1
'ÕâÒ»¶ÎÊǺϲ¢ÇøÓò
' If SPos <= Epos Then
' If Bind Then
' Pt(2).x = SPos
' Pt(2).y = y
' Pt(3).x = Epos
' Pt(3).y = y
Rgn2 = CreateRectRgn(SPos, Y, Epos, Y + 1)
'Rgn2 = CreatePolygonRgn(Pt(0), 4, 1)
CombineRgn Rgn1, Rgn1, Rgn2, RGN_OR
DeleteObject Rgn2
' Bind = False
' Else
' Pt(0).x = SPos
' Pt(0).y = y
' Pt(1).x = Epos
' Pt(1).y = y
' Bind = True
' End If
' End If
End If
Loop Until X >= Wid
Next Y
Erase bmByte
'É趨´°ÌåÐÎ×´ÇøÓò
SetWindowRgn hForm.hWnd, Rgn1, True
DeleteObject Rgn1
End Sub