SetByteData Method Example

SetByteData Method Example

This example shows you how to copy the byte data into a byte array. To try the example, place a Command Button on your form and paste the code into your form's module. Then run the example.

'Declarations
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
        (Destination As Any, Source As Any, ByVal ByteLen As Long)

Private Sub cmdCopyMemory_Click()
  Dim ByteCopy() As Byte
  Dim strFileName As String
  Dim BMU As VWBitmapUtils.BitmapUtils
  
  'Initialize the BitmapUtils object.
  Set BMU = New VWBitmapUtils.BitmapUtils
  
  strFileName = "C:\WINDOWS\Coffee Bean.bmp"
  
  'Load the Bitmap into memory.
  Call BMU.LoadByteData(strFileName)
  
  'Redim the byte array.
  ReDim ByteCopy(BMU.ByteDataLen - 1)
  
  'Copy the byte data into the byte array.
  Call CopyMemory(ByteCopy(LBound(ByteCopy)), ByVal BMU.ByteData, BMU.ByteDataLen)
  
  'Here, you might use another compression/encryption system to manipulate the byte data.
  
  'Copy your byte array back into the library's byte data.
  Call BMU.SetByteData(VarPtr(ByteCopy(LBound(ByteCopy))), (UBound(ByteCopy) - LBound(ByteCopy)) + 1)
End Sub