This should help you if you do decide to use a picture box or if you decide to use a DC instead of the picture box see this thread http://www.vbforums.com/showthread.p...hreadid=210500 which sequoyan will already know of. This example inverts each pixel.
VB Code:
Private Declare Function VarPtrArray Lib "msvbvm50.dll" Alias "VarPtr" (Ptr() As Any) As Long Private Declare Function VarPtr Lib "msvbvm50.dll" (Ptr As Any) As Long Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) Private Declare Function GetObjectAPI Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long Private Type SAFEARRAYBOUND cElements As Long lLbound As Long End Type Private Type SAFEARRAY2D cDims As Integer fFeatures As Integer cbElements As Long cLocks As Long pvData As Long Bounds(0 To 1) As SAFEARRAYBOUND End Type Private 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 'Code Dim i As Integer Dim j As Integer Dim pic() As Byte Dim sa As SAFEARRAY2D Dim bmp As BITMAP Dim r As Long, g As Long, b As Long GetObjectAPI Picture1.Picture, Len(bmp), bmp With sa .cbElements = 1 .cDims = 2 .Bounds(0).lLbound = 0 .Bounds(0).cElements = bmp.bmHeight .Bounds(1).lLbound = 0 .Bounds(1).cElements = bmp.bmWidthBytes .pvData = bmp.bmBits End With CopyMemory ByVal VarPtrArray(pic), VarPtr(sa), 4 For i = 0 To UBound(pic, 1) - 3 Step 3 For j = 0 To UBound(pic, 2) r = pic(i + 2, j) g = pic(i + 1, j) b = pic(i, j) pic(i, j) = 255 - b pic(i + 1, j) = 255 - g pic(i + 2, j) = 255 - r Next Next CopyMemory ByVal VarPtrArray(pic), 0&, 4




)
Reply With Quote