Results 1 to 4 of 4

Thread: Bmp manipulation with pointer <problem> **[RESOLVED]**

Threaded View

  1. #1

    Thread Starter
    Addicted Member Aldragor's Avatar
    Join Date
    Oct 2002
    Location
    Québec, Canada
    Posts
    140

    Bmp manipulation with pointer <problem> **[RESOLVED]**

    I try out the pointer methode to transform a bitmap and I have the error : Type mismatch, Array or User defined type expected.

    on the line> CopyMemory ByVal VarPtrArray(pic), VarPtrArray(sa), 4

    I am using VB6, and I don't find what I have done wrong!

    VB Code:
    1. Option Explicit
    2.  
    3. Private Type SAFEARRAYBOUND
    4.     cElements As Long
    5.     lLbound As Long
    6. End Type
    7.  
    8. Private Type SAFEARRAY2D
    9.     cDims As Integer
    10.     fFeatures As Integer
    11.     cbElements As Long
    12.     cLocks As Long
    13.     pvData As Long
    14.     Bounds(0 To 1) As SAFEARRAYBOUND
    15. End Type
    16.  
    17. Private Type BITMAP '14 bytes
    18.     bmType As Long
    19.     bmWidth As Long
    20.     bmHeight As Long
    21.     bmWidthBytes As Long
    22.     bmPlanes As Integer
    23.     bmBitsPixel As Integer
    24.     bmBits As Long
    25. End Type
    26.  
    27. Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" (Ptr() As Any) As Long
    28. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
    29. Private Declare Function GetObjectAPI Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
    30.  
    31. Dim pic() As Byte
    32. Dim sa As SAFEARRAY2D
    33. Dim bmp As BITMAP
    34. Dim r As Long, g As Long, b As Long
    35. Dim i As Integer, j As Integer
    36.  
    37. Dim picFileName As String
    38. Dim picOrig As StdPicture
    39.  
    40. Private Sub Command1_Click()
    41.     dlg1.FileName = ""
    42.     dlg1.Flags = &H1000& Or &H4&
    43.     dlg1.ShowOpen
    44.     If dlg1.FileName <> "" Then
    45.         picFileName = dlg1.FileName
    46.         Picture1.Picture = LoadPicture(picFileName)
    47.         Set picOrig = Picture1.Picture
    48.     End If
    49. End Sub
    50.  
    51. Private Sub Command2_Click()
    52.     dlg1.Flags = &H2
    53.     dlg1.ShowColor
    54.     selectedColor.BackColor = dlg1.Color
    55. End Sub
    56.  
    57. Private Sub Command3_Click()
    58.     If picOrig <> 0 Then
    59.         Set Picture1.Picture = picOrig
    60.     End If
    61. End Sub
    62.  
    63. Private Sub Command4_Click()
    64.     GetObjectAPI Picture1.Picture, Len(bmp), bmp
    65.    
    66.     sa.cbElements = 1
    67.     sa.cDims = 2
    68.     sa.Bounds(0).lLbound = 0
    69.     sa.Bounds(0).cElements = bmp.bmHeight
    70.     sa.Bounds(1).lLbound = 0
    71.     sa.Bounds(1).cElements = bmp.bmWidthBytes
    72.     sa.pvData = bmp.bmBits
    73.    
    74.     CopyMemory ByVal VarPtrArray(pic), VarPtrArray(sa), 4
    75.    
    76.     For i = 0 To UBound(pic, 1) - 3 Step 3
    77.         For j = 0 To UBound(pic, 2)
    78.             pic(i, j) = 255 - pic(i, j)
    79.         Next j
    80.     Next i
    81.    
    82.     CopyMemory ByVal VarPtrArray(pic), 0&, 4 'delete array
    83.    
    84.     Picture1.Refresh
    85. End Sub


    The code in VB6 is attached... ready to run if you want to try it!
    Attached Files Attached Files
    Last edited by Aldragor; Nov 7th, 2002 at 04:58 PM.
    Mens sana in corpore sano
    ... pour mieux travailler!

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