Home All Groups Group Topic Archive Search About
Author
19 Jul 2006 5:14 PM
Aristotelis Pitaridis
Can someone convert the vb6 code below to vb.net. I have spent several hours
but I can not make it.
I have attached the code in a txt file

Option Explicit

Private Const BMP_MAGIC_COOKIE As Integer = 19778 'this is equivalent to
ascii string "BM"

Private m_bih As BITMAPINFOHEADER
Private m_bfh As BITMAPFILEHEADER
Private m_memBitmapInfo() As Byte
Private m_memBits() As Byte

Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory"
(ByRef dest As Any, ByRef src As Any, ByVal dwLen As Long)

Private Type BITMAPFILEHEADER '14 bytes
        bfType As Integer '"magic cookie" - must be "BM"
        bfSize As Long
        bfReserved1 As Integer
        bfReserved2 As Integer
        bfOffBits As Long
End Type

Private Type BITMAPINFOHEADER '40 bytes
   biSize As Long
   biWidth As Long
   biHeight As Long
   biPlanes As Integer
   biBitCount As Integer
   biCompression As Long
   biSizeImage As Long
   biXPelsPerMeter As Long
   biYPelsPerMeter As Long
   biClrUsed As Long
   biClrImportant As Long
End Type


Public Function CreateFromPackedDIBPointer(ByRef pDIB As Long) As Boolean
    Debug.Assert pDIB <> 0
    'Creates a full-color (no palette) DIB from a pointer to a full-color
memory DIB

    'get the BitmapInfoHeader
    Call CopyMemory(ByVal VarPtr(m_bih.biSize), ByVal pDIB, Len(m_bih))
    If m_bih.biBitCount < 16 Then
        Debug.Print "Error! DIB was less than 16 colors."
        Exit Function 'only supports high-color or full-color dibs
    End If

    'now get the bitmap bits
    If m_bih.biSizeImage < 1 Then Exit Function 'return False
    ReDim m_memBits(0 To m_bih.biSizeImage - 1)
    Call CopyMemory(m_memBits(0), ByVal pDIB + 40, m_bih.biSizeImage)

    'and BitmapInfo variable-length UDT
    ReDim m_memBitmapInfo(0 To 39) 'don't need first 14 bytes (fileinfo)
    Call CopyMemory(m_memBitmapInfo(0), m_bih, Len(m_bih))

    'create a file header
    With m_bfh
        .bfType = BMP_MAGIC_COOKIE
        .bfSize = 55 + m_bih.biSizeImage 'size of file as written to disk
        .bfReserved1 = 0&
        .bfReserved2 = 0&
        .bfOffBits = 54 'BitmapInfoHeader + BitmapFileHeader
    End With

    'and return True
    CreateFromPackedDIBPointer = True
End Function

Public Function WriteToFile(ByVal filename As String) As Boolean
    Dim hFile As Integer
    On Error Resume Next
    hFile = FreeFile()
    Open filename For Binary As hFile
        Put hFile, 1, m_bfh
        Put hFile, Len(m_bfh) + 1, m_memBitmapInfo
        Put hFile, , m_memBits
    Close hFile
    WriteToFile = True
End Function

[attached file: code.txt]

Author
19 Jul 2006 4:49 PM
Patrice
I don't have time (and perhaps knowledge) for the whole job but you could
perhaps tell us at which point you are. For example have you translated VB6
Long values to VB.NET Integer values ?

Not an expert but you may want also to check if this could be doable more
easily in .NET. For example if you can use the Bitmap constructor
http://msdn2.microsoft.com/en-us/library/zy1a2d14.aspx to create your
bitmaps from the pointer you could then just save the bitmap using the Save
Method.
http://msdn2.microsoft.com/en-us/library/system.drawing.image.save.aspx
resulting in a much simpler/clear code...

--
Patrice

"Aristotelis Pitaridis" <pitari***@hotmail.com> a écrit dans le message de
news: 1153325492.148373@athnrd02...
Show quoteHide quote
> Can someone convert the vb6 code below to vb.net. I have spent several
> hours but I can not make it.
> I have attached the code in a txt file
>
> Option Explicit
>
> Private Const BMP_MAGIC_COOKIE As Integer = 19778 'this is equivalent to
> ascii string "BM"
>
> Private m_bih As BITMAPINFOHEADER
> Private m_bfh As BITMAPFILEHEADER
> Private m_memBitmapInfo() As Byte
> Private m_memBits() As Byte
>
> Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory"
> (ByRef dest As Any, ByRef src As Any, ByVal dwLen As Long)
>
> Private Type BITMAPFILEHEADER '14 bytes
>        bfType As Integer '"magic cookie" - must be "BM"
>        bfSize As Long
>        bfReserved1 As Integer
>        bfReserved2 As Integer
>        bfOffBits As Long
> End Type
>
> Private Type BITMAPINFOHEADER '40 bytes
>   biSize As Long
>   biWidth As Long
>   biHeight As Long
>   biPlanes As Integer
>   biBitCount As Integer
>   biCompression As Long
>   biSizeImage As Long
>   biXPelsPerMeter As Long
>   biYPelsPerMeter As Long
>   biClrUsed As Long
>   biClrImportant As Long
> End Type
>
>
> Public Function CreateFromPackedDIBPointer(ByRef pDIB As Long) As Boolean
>    Debug.Assert pDIB <> 0
>    'Creates a full-color (no palette) DIB from a pointer to a full-color
> memory DIB
>
>    'get the BitmapInfoHeader
>    Call CopyMemory(ByVal VarPtr(m_bih.biSize), ByVal pDIB, Len(m_bih))
>    If m_bih.biBitCount < 16 Then
>        Debug.Print "Error! DIB was less than 16 colors."
>        Exit Function 'only supports high-color or full-color dibs
>    End If
>
>    'now get the bitmap bits
>    If m_bih.biSizeImage < 1 Then Exit Function 'return False
>    ReDim m_memBits(0 To m_bih.biSizeImage - 1)
>    Call CopyMemory(m_memBits(0), ByVal pDIB + 40, m_bih.biSizeImage)
>
>    'and BitmapInfo variable-length UDT
>    ReDim m_memBitmapInfo(0 To 39) 'don't need first 14 bytes (fileinfo)
>    Call CopyMemory(m_memBitmapInfo(0), m_bih, Len(m_bih))
>
>    'create a file header
>    With m_bfh
>        .bfType = BMP_MAGIC_COOKIE
>        .bfSize = 55 + m_bih.biSizeImage 'size of file as written to disk
>        .bfReserved1 = 0&
>        .bfReserved2 = 0&
>        .bfOffBits = 54 'BitmapInfoHeader + BitmapFileHeader
>    End With
>
>    'and return True
>    CreateFromPackedDIBPointer = True
> End Function
>
> Public Function WriteToFile(ByVal filename As String) As Boolean
>    Dim hFile As Integer
>    On Error Resume Next
>    hFile = FreeFile()
>    Open filename For Binary As hFile
>        Put hFile, 1, m_bfh
>        Put hFile, Len(m_bfh) + 1, m_memBitmapInfo
>        Put hFile, , m_memBits
>    Close hFile
>    WriteToFile = True
> End Function
>
>
>
Author
19 Jul 2006 6:02 PM
Aristotelis Pitaridis
My main problem is the third call of CopyMemory in the
CreateFromPackedDIBPointer function.

Thanks

Show quoteHide quote
Ï "Patrice" <scr***@chez.com> Ýãñáøå óôï ìÞíõìá
news:endzDN1qGHA.4492@TK2MSFTNGP05.phx.gbl...
>
> I don't have time (and perhaps knowledge) for the whole job but you could
> perhaps tell us at which point you are. For example have you translated
> VB6 Long values to VB.NET Integer values ?
>
> Not an expert but you may want also to check if this could be doable more
> easily in .NET. For example if you can use the Bitmap constructor
> http://msdn2.microsoft.com/en-us/library/zy1a2d14.aspx to create your
> bitmaps from the pointer you could then just save the bitmap using the
> Save Method.
> http://msdn2.microsoft.com/en-us/library/system.drawing.image.save.aspx
> resulting in a much simpler/clear code...
>
> --
> Patrice
>
> "Aristotelis Pitaridis" <pitari***@hotmail.com> a écrit dans le message de
> news: 1153325492.148373@athnrd02...
>> Can someone convert the vb6 code below to vb.net. I have spent several
>> hours but I can not make it.
>> I have attached the code in a txt file
>>
>> Option Explicit
>>
>> Private Const BMP_MAGIC_COOKIE As Integer = 19778 'this is equivalent to
>> ascii string "BM"
>>
>> Private m_bih As BITMAPINFOHEADER
>> Private m_bfh As BITMAPFILEHEADER
>> Private m_memBitmapInfo() As Byte
>> Private m_memBits() As Byte
>>
>> Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory"
>> (ByRef dest As Any, ByRef src As Any, ByVal dwLen As Long)
>>
>> Private Type BITMAPFILEHEADER '14 bytes
>>        bfType As Integer '"magic cookie" - must be "BM"
>>        bfSize As Long
>>        bfReserved1 As Integer
>>        bfReserved2 As Integer
>>        bfOffBits As Long
>> End Type
>>
>> Private Type BITMAPINFOHEADER '40 bytes
>>   biSize As Long
>>   biWidth As Long
>>   biHeight As Long
>>   biPlanes As Integer
>>   biBitCount As Integer
>>   biCompression As Long
>>   biSizeImage As Long
>>   biXPelsPerMeter As Long
>>   biYPelsPerMeter As Long
>>   biClrUsed As Long
>>   biClrImportant As Long
>> End Type
>>
>>
>> Public Function CreateFromPackedDIBPointer(ByRef pDIB As Long) As Boolean
>>    Debug.Assert pDIB <> 0
>>    'Creates a full-color (no palette) DIB from a pointer to a full-color
>> memory DIB
>>
>>    'get the BitmapInfoHeader
>>    Call CopyMemory(ByVal VarPtr(m_bih.biSize), ByVal pDIB, Len(m_bih))
>>    If m_bih.biBitCount < 16 Then
>>        Debug.Print "Error! DIB was less than 16 colors."
>>        Exit Function 'only supports high-color or full-color dibs
>>    End If
>>
>>    'now get the bitmap bits
>>    If m_bih.biSizeImage < 1 Then Exit Function 'return False
>>    ReDim m_memBits(0 To m_bih.biSizeImage - 1)
>>    Call CopyMemory(m_memBits(0), ByVal pDIB + 40, m_bih.biSizeImage)
>>
>>    'and BitmapInfo variable-length UDT
>>    ReDim m_memBitmapInfo(0 To 39) 'don't need first 14 bytes (fileinfo)
>>    Call CopyMemory(m_memBitmapInfo(0), m_bih, Len(m_bih))
>>
>>    'create a file header
>>    With m_bfh
>>        .bfType = BMP_MAGIC_COOKIE
>>        .bfSize = 55 + m_bih.biSizeImage 'size of file as written to disk
>>        .bfReserved1 = 0&
>>        .bfReserved2 = 0&
>>        .bfOffBits = 54 'BitmapInfoHeader + BitmapFileHeader
>>    End With
>>
>>    'and return True
>>    CreateFromPackedDIBPointer = True
>> End Function
>>
>> Public Function WriteToFile(ByVal filename As String) As Boolean
>>    Dim hFile As Integer
>>    On Error Resume Next
>>    hFile = FreeFile()
>>    Open filename For Binary As hFile
>>        Put hFile, 1, m_bfh
>>        Put hFile, Len(m_bfh) + 1, m_memBitmapInfo
>>        Put hFile, , m_memBits
>>    Close hFile
>>    WriteToFile = True
>> End Function
>>
>>
>>
>
>
Author
19 Jul 2006 5:54 PM
Patrice
The exact problem being ?

What is the overall goal of the code ?. To learn more I'm currently looking
at getting data from the clipboard as a DIB and saving this as a file.

--
Patrice

"Aristotelis Pitaridis" <pitari***@hotmail.com> a écrit dans le message de
news: 1153328418.851080@athnrd02...
Show quoteHide quote
> My main problem is the third call of CopyMemory in the
> CreateFromPackedDIBPointer function.
>
> Thanks
>
> Ï "Patrice" <scr***@chez.com> Ýãñáøå óôï ìÞíõìá
> news:endzDN1qGHA.4492@TK2MSFTNGP05.phx.gbl...
>>
>> I don't have time (and perhaps knowledge) for the whole job but you could
>> perhaps tell us at which point you are. For example have you translated
>> VB6 Long values to VB.NET Integer values ?
>>
>> Not an expert but you may want also to check if this could be doable more
>> easily in .NET. For example if you can use the Bitmap constructor
>> http://msdn2.microsoft.com/en-us/library/zy1a2d14.aspx to create your
>> bitmaps from the pointer you could then just save the bitmap using the
>> Save Method.
>> http://msdn2.microsoft.com/en-us/library/system.drawing.image.save.aspx
>> resulting in a much simpler/clear code...
>>
>> --
>> Patrice
>>
>> "Aristotelis Pitaridis" <pitari***@hotmail.com> a écrit dans le message
>> de news: 1153325492.148373@athnrd02...
>>> Can someone convert the vb6 code below to vb.net. I have spent several
>>> hours but I can not make it.
>>> I have attached the code in a txt file
>>>
>>> Option Explicit
>>>
>>> Private Const BMP_MAGIC_COOKIE As Integer = 19778 'this is equivalent to
>>> ascii string "BM"
>>>
>>> Private m_bih As BITMAPINFOHEADER
>>> Private m_bfh As BITMAPFILEHEADER
>>> Private m_memBitmapInfo() As Byte
>>> Private m_memBits() As Byte
>>>
>>> Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory"
>>> (ByRef dest As Any, ByRef src As Any, ByVal dwLen As Long)
>>>
>>> Private Type BITMAPFILEHEADER '14 bytes
>>>        bfType As Integer '"magic cookie" - must be "BM"
>>>        bfSize As Long
>>>        bfReserved1 As Integer
>>>        bfReserved2 As Integer
>>>        bfOffBits As Long
>>> End Type
>>>
>>> Private Type BITMAPINFOHEADER '40 bytes
>>>   biSize As Long
>>>   biWidth As Long
>>>   biHeight As Long
>>>   biPlanes As Integer
>>>   biBitCount As Integer
>>>   biCompression As Long
>>>   biSizeImage As Long
>>>   biXPelsPerMeter As Long
>>>   biYPelsPerMeter As Long
>>>   biClrUsed As Long
>>>   biClrImportant As Long
>>> End Type
>>>
>>>
>>> Public Function CreateFromPackedDIBPointer(ByRef pDIB As Long) As
>>> Boolean
>>>    Debug.Assert pDIB <> 0
>>>    'Creates a full-color (no palette) DIB from a pointer to a full-color
>>> memory DIB
>>>
>>>    'get the BitmapInfoHeader
>>>    Call CopyMemory(ByVal VarPtr(m_bih.biSize), ByVal pDIB, Len(m_bih))
>>>    If m_bih.biBitCount < 16 Then
>>>        Debug.Print "Error! DIB was less than 16 colors."
>>>        Exit Function 'only supports high-color or full-color dibs
>>>    End If
>>>
>>>    'now get the bitmap bits
>>>    If m_bih.biSizeImage < 1 Then Exit Function 'return False
>>>    ReDim m_memBits(0 To m_bih.biSizeImage - 1)
>>>    Call CopyMemory(m_memBits(0), ByVal pDIB + 40, m_bih.biSizeImage)
>>>
>>>    'and BitmapInfo variable-length UDT
>>>    ReDim m_memBitmapInfo(0 To 39) 'don't need first 14 bytes (fileinfo)
>>>    Call CopyMemory(m_memBitmapInfo(0), m_bih, Len(m_bih))
>>>
>>>    'create a file header
>>>    With m_bfh
>>>        .bfType = BMP_MAGIC_COOKIE
>>>        .bfSize = 55 + m_bih.biSizeImage 'size of file as written to disk
>>>        .bfReserved1 = 0&
>>>        .bfReserved2 = 0&
>>>        .bfOffBits = 54 'BitmapInfoHeader + BitmapFileHeader
>>>    End With
>>>
>>>    'and return True
>>>    CreateFromPackedDIBPointer = True
>>> End Function
>>>
>>> Public Function WriteToFile(ByVal filename As String) As Boolean
>>>    Dim hFile As Integer
>>>    On Error Resume Next
>>>    hFile = FreeFile()
>>>    Open filename For Binary As hFile
>>>        Put hFile, 1, m_bfh
>>>        Put hFile, Len(m_bfh) + 1, m_memBitmapInfo
>>>        Put hFile, , m_memBits
>>>    Close hFile
>>>    WriteToFile = True
>>> End Function
>>>
>>>
>>>
>>
>>
>
>
Author
20 Jul 2006 7:08 AM
Aristotelis Pitaridis
The goal of the project is to extract BMP images from an AVI file.
I have attached the initial project in VB6.


Show quoteHide quote
Ï "Patrice" <scr***@chez.com> Ýãñáøå óôï ìÞíõìá
news:O7sptx1qGHA.2256@TK2MSFTNGP03.phx.gbl...
>
> The exact problem being ?
>
> What is the overall goal of the code ?. To learn more I'm currently
> looking
> at getting data from the clipboard as a DIB and saving this as a file.
>
> --
> Patrice
>
> "Aristotelis Pitaridis" <pitari***@hotmail.com> a écrit dans le message de
> news: 1153328418.851080@athnrd02...
>> My main problem is the third call of CopyMemory in the
>> CreateFromPackedDIBPointer function.
>>
>> Thanks
>>
>> Ï "Patrice" <scr***@chez.com> Ýãñáøå óôï ìÞíõìá
>> news:endzDN1qGHA.4492@TK2MSFTNGP05.phx.gbl...
>>>
>>> I don't have time (and perhaps knowledge) for the whole job but you
>>> could
>>> perhaps tell us at which point you are. For example have you translated
>>> VB6 Long values to VB.NET Integer values ?
>>>
>>> Not an expert but you may want also to check if this could be doable
>>> more
>>> easily in .NET. For example if you can use the Bitmap constructor
>>> http://msdn2.microsoft.com/en-us/library/zy1a2d14.aspx to create your
>>> bitmaps from the pointer you could then just save the bitmap using the
>>> Save Method.
>>> http://msdn2.microsoft.com/en-us/library/system.drawing.image.save.aspx
>>> resulting in a much simpler/clear code...
>>>
>>> --
>>> Patrice
>>>
>>> "Aristotelis Pitaridis" <pitari***@hotmail.com> a écrit dans le message
>>> de news: 1153325492.148373@athnrd02...
>>>> Can someone convert the vb6 code below to vb.net. I have spent several
>>>> hours but I can not make it.
>>>> I have attached the code in a txt file
>>>>
>>>> Option Explicit
>>>>
>>>> Private Const BMP_MAGIC_COOKIE As Integer = 19778 'this is equivalent
>>>> to
>>>> ascii string "BM"
>>>>
>>>> Private m_bih As BITMAPINFOHEADER
>>>> Private m_bfh As BITMAPFILEHEADER
>>>> Private m_memBitmapInfo() As Byte
>>>> Private m_memBits() As Byte
>>>>
>>>> Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory"
>>>> (ByRef dest As Any, ByRef src As Any, ByVal dwLen As Long)
>>>>
>>>> Private Type BITMAPFILEHEADER '14 bytes
>>>>        bfType As Integer '"magic cookie" - must be "BM"
>>>>        bfSize As Long
>>>>        bfReserved1 As Integer
>>>>        bfReserved2 As Integer
>>>>        bfOffBits As Long
>>>> End Type
>>>>
>>>> Private Type BITMAPINFOHEADER '40 bytes
>>>>   biSize As Long
>>>>   biWidth As Long
>>>>   biHeight As Long
>>>>   biPlanes As Integer
>>>>   biBitCount As Integer
>>>>   biCompression As Long
>>>>   biSizeImage As Long
>>>>   biXPelsPerMeter As Long
>>>>   biYPelsPerMeter As Long
>>>>   biClrUsed As Long
>>>>   biClrImportant As Long
>>>> End Type
>>>>
>>>>
>>>> Public Function CreateFromPackedDIBPointer(ByRef pDIB As Long) As
>>>> Boolean
>>>>    Debug.Assert pDIB <> 0
>>>>    'Creates a full-color (no palette) DIB from a pointer to a
>>>> full-color
>>>> memory DIB
>>>>
>>>>    'get the BitmapInfoHeader
>>>>    Call CopyMemory(ByVal VarPtr(m_bih.biSize), ByVal pDIB, Len(m_bih))
>>>>    If m_bih.biBitCount < 16 Then
>>>>        Debug.Print "Error! DIB was less than 16 colors."
>>>>        Exit Function 'only supports high-color or full-color dibs
>>>>    End If
>>>>
>>>>    'now get the bitmap bits
>>>>    If m_bih.biSizeImage < 1 Then Exit Function 'return False
>>>>    ReDim m_memBits(0 To m_bih.biSizeImage - 1)
>>>>    Call CopyMemory(m_memBits(0), ByVal pDIB + 40, m_bih.biSizeImage)
>>>>
>>>>    'and BitmapInfo variable-length UDT
>>>>    ReDim m_memBitmapInfo(0 To 39) 'don't need first 14 bytes (fileinfo)
>>>>    Call CopyMemory(m_memBitmapInfo(0), m_bih, Len(m_bih))
>>>>
>>>>    'create a file header
>>>>    With m_bfh
>>>>        .bfType = BMP_MAGIC_COOKIE
>>>>        .bfSize = 55 + m_bih.biSizeImage 'size of file as written to
>>>> disk
>>>>        .bfReserved1 = 0&
>>>>        .bfReserved2 = 0&
>>>>        .bfOffBits = 54 'BitmapInfoHeader + BitmapFileHeader
>>>>    End With
>>>>
>>>>    'and return True
>>>>    CreateFromPackedDIBPointer = True
>>>> End Function
>>>>
>>>> Public Function WriteToFile(ByVal filename As String) As Boolean
>>>>    Dim hFile As Integer
>>>>    On Error Resume Next
>>>>    hFile = FreeFile()
>>>>    Open filename For Binary As hFile
>>>>        Put hFile, 1, m_bfh
>>>>        Put hFile, Len(m_bfh) + 1, m_memBitmapInfo
>>>>        Put hFile, , m_memBits
>>>>    Close hFile
>>>>    WriteToFile = True
>>>> End Function
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>

[attached file: avitutr3.zip]
Author
19 Jul 2006 6:06 PM
Patrice
Or you could try :
http://pinvoke.net/default.aspx/gdiplus.GdipCreateBitmapFromGdiDib

(along with GdipSaveImageToFile).

--
Patrice

"Aristotelis Pitaridis" <pitari***@hotmail.com> a écrit dans le message de
news: 1153328418.851080@athnrd02...
Show quoteHide quote
> My main problem is the third call of CopyMemory in the
> CreateFromPackedDIBPointer function.
>
> Thanks
>
> Ï "Patrice" <scr***@chez.com> Ýãñáøå óôï ìÞíõìá
> news:endzDN1qGHA.4492@TK2MSFTNGP05.phx.gbl...
>>
>> I don't have time (and perhaps knowledge) for the whole job but you could
>> perhaps tell us at which point you are. For example have you translated
>> VB6 Long values to VB.NET Integer values ?
>>
>> Not an expert but you may want also to check if this could be doable more
>> easily in .NET. For example if you can use the Bitmap constructor
>> http://msdn2.microsoft.com/en-us/library/zy1a2d14.aspx to create your
>> bitmaps from the pointer you could then just save the bitmap using the
>> Save Method.
>> http://msdn2.microsoft.com/en-us/library/system.drawing.image.save.aspx
>> resulting in a much simpler/clear code...
>>
>> --
>> Patrice
>>
>> "Aristotelis Pitaridis" <pitari***@hotmail.com> a écrit dans le message
>> de news: 1153325492.148373@athnrd02...
>>> Can someone convert the vb6 code below to vb.net. I have spent several
>>> hours but I can not make it.
>>> I have attached the code in a txt file
>>>
>>> Option Explicit
>>>
>>> Private Const BMP_MAGIC_COOKIE As Integer = 19778 'this is equivalent to
>>> ascii string "BM"
>>>
>>> Private m_bih As BITMAPINFOHEADER
>>> Private m_bfh As BITMAPFILEHEADER
>>> Private m_memBitmapInfo() As Byte
>>> Private m_memBits() As Byte
>>>
>>> Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory"
>>> (ByRef dest As Any, ByRef src As Any, ByVal dwLen As Long)
>>>
>>> Private Type BITMAPFILEHEADER '14 bytes
>>>        bfType As Integer '"magic cookie" - must be "BM"
>>>        bfSize As Long
>>>        bfReserved1 As Integer
>>>        bfReserved2 As Integer
>>>        bfOffBits As Long
>>> End Type
>>>
>>> Private Type BITMAPINFOHEADER '40 bytes
>>>   biSize As Long
>>>   biWidth As Long
>>>   biHeight As Long
>>>   biPlanes As Integer
>>>   biBitCount As Integer
>>>   biCompression As Long
>>>   biSizeImage As Long
>>>   biXPelsPerMeter As Long
>>>   biYPelsPerMeter As Long
>>>   biClrUsed As Long
>>>   biClrImportant As Long
>>> End Type
>>>
>>>
>>> Public Function CreateFromPackedDIBPointer(ByRef pDIB As Long) As
>>> Boolean
>>>    Debug.Assert pDIB <> 0
>>>    'Creates a full-color (no palette) DIB from a pointer to a full-color
>>> memory DIB
>>>
>>>    'get the BitmapInfoHeader
>>>    Call CopyMemory(ByVal VarPtr(m_bih.biSize), ByVal pDIB, Len(m_bih))
>>>    If m_bih.biBitCount < 16 Then
>>>        Debug.Print "Error! DIB was less than 16 colors."
>>>        Exit Function 'only supports high-color or full-color dibs
>>>    End If
>>>
>>>    'now get the bitmap bits
>>>    If m_bih.biSizeImage < 1 Then Exit Function 'return False
>>>    ReDim m_memBits(0 To m_bih.biSizeImage - 1)
>>>    Call CopyMemory(m_memBits(0), ByVal pDIB + 40, m_bih.biSizeImage)
>>>
>>>    'and BitmapInfo variable-length UDT
>>>    ReDim m_memBitmapInfo(0 To 39) 'don't need first 14 bytes (fileinfo)
>>>    Call CopyMemory(m_memBitmapInfo(0), m_bih, Len(m_bih))
>>>
>>>    'create a file header
>>>    With m_bfh
>>>        .bfType = BMP_MAGIC_COOKIE
>>>        .bfSize = 55 + m_bih.biSizeImage 'size of file as written to disk
>>>        .bfReserved1 = 0&
>>>        .bfReserved2 = 0&
>>>        .bfOffBits = 54 'BitmapInfoHeader + BitmapFileHeader
>>>    End With
>>>
>>>    'and return True
>>>    CreateFromPackedDIBPointer = True
>>> End Function
>>>
>>> Public Function WriteToFile(ByVal filename As String) As Boolean
>>>    Dim hFile As Integer
>>>    On Error Resume Next
>>>    hFile = FreeFile()
>>>    Open filename For Binary As hFile
>>>        Put hFile, 1, m_bfh
>>>        Put hFile, Len(m_bfh) + 1, m_memBitmapInfo
>>>        Put hFile, , m_memBits
>>>    Close hFile
>>>    WriteToFile = True
>>> End Function
>>>
>>>
>>>
>>
>>
>
>