Ok I have this bit of code I picked up from planet-source-code that shapes forms around a bitmap, however I was wondering if there was any way to speed it up for bigger images or animations any help would be greatly appreciated:


public Declare Function GetPixel Lib "gdi32" (byval hdc as Long, byval X as Long, byval Y 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
Declare Sub ReleaseCapture Lib "user32" ()
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (byval hwnd as Long, byval wMsg as Long, byval wParam as Long, lParam as Any) as Long
public Declare Function DeleteObject Lib "gdi32" (byval hObject as Long) as Long



Sub TRANSP(bg as Form, bgcolor as OLE_COLOR)
Dim rgn as Long, rgn2 as Long, rgn3 as Long, rgn4 as Long
Dim x1 as Long, y1 as Long, i as Long, j as Long, tj as Long
rgn = CreateRectRgn(0, 0, 0, 0)
rgn2 = CreateRectRgn(0, 0, 0, 0)
rgn3 = CreateRectRgn(0, 0, 0, 0)
i = 1
x1 = bg.Width / Screen.TwipsPerPixelX
y1 = bg.Height / Screen.TwipsPerPixelY
Do While i < x1
j = 1
Do While j < y1
If GetPixel(bg.hdc, i, j) <> bgcolor then
tj = j
Do While GetPixel(bg.hdc, i, j + 1) <> bgcolor
j = j + 1
If j = y1 then Exit Do
Loop
rgn4 = CreateRectRgn(i, tj, i + 1, j + 1)
CombineRgn rgn3, rgn2, rgn2, 5
CombineRgn rgn2, rgn4, rgn3, 2
DeleteObject rgn4
End If
j = j + 1
Loop
CombineRgn rgn3, rgn, rgn, 5
CombineRgn rgn, rgn2, rgn3, 2
i = i + 1
Loop
DeleteObject rgn2
SetWindowRgn bg.hwnd, rgn, true
End Sub