Results 1 to 9 of 9

Thread: fastest byte array of a bitmap ?

Hybrid View

  1. #1
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    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:
    1. Private Declare Function VarPtrArray Lib "msvbvm50.dll" Alias "VarPtr" (Ptr() As Any) As Long
    2. Private Declare Function VarPtr Lib "msvbvm50.dll" (Ptr As Any) As Long
    3. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    4. Private Declare Function GetObjectAPI Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
    5.  
    6. Private Type SAFEARRAYBOUND
    7.     cElements As Long
    8.     lLbound As Long
    9. End Type
    10.  
    11. Private Type SAFEARRAY2D
    12.     cDims As Integer
    13.     fFeatures As Integer
    14.     cbElements As Long
    15.     cLocks As Long
    16.     pvData As Long
    17.     Bounds(0 To 1) As SAFEARRAYBOUND
    18. End Type
    19.  
    20. Private Type BITMAP
    21.     bmType As Long
    22.     bmWidth As Long
    23.     bmHeight As Long
    24.     bmWidthBytes As Long
    25.     bmPlanes As Integer
    26.     bmBitsPixel As Integer
    27.     bmBits As Long
    28. End Type
    29.  
    30.  
    31. 'Code
    32. Dim i As Integer
    33. Dim j As Integer
    34. Dim pic() As Byte
    35. Dim sa As SAFEARRAY2D
    36. Dim bmp As BITMAP
    37. Dim r As Long, g As Long, b As Long
    38.  
    39. GetObjectAPI Picture1.Picture, Len(bmp), bmp
    40.  
    41. With sa
    42.     .cbElements = 1
    43.     .cDims = 2
    44.     .Bounds(0).lLbound = 0
    45.     .Bounds(0).cElements = bmp.bmHeight
    46.     .Bounds(1).lLbound = 0
    47.     .Bounds(1).cElements = bmp.bmWidthBytes
    48.     .pvData = bmp.bmBits
    49. End With
    50.  
    51. CopyMemory ByVal VarPtrArray(pic), VarPtr(sa), 4
    52.  
    53. For i = 0 To UBound(pic, 1) - 3 Step 3
    54.     For j = 0 To UBound(pic, 2)
    55.         r = pic(i + 2, j)
    56.         g = pic(i + 1, j)
    57.         b = pic(i, j)
    58.         pic(i, j) = 255 - b
    59.         pic(i + 1, j) = 255 - g
    60.         pic(i + 2, j) = 255 - r
    61.     Next
    62. Next
    63.  
    64. CopyMemory ByVal VarPtrArray(pic), 0&, 4
    Last edited by Electroman; Nov 2nd, 2002 at 03:02 PM.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width