Clipboard's Memory

Hi :)

How can I read the clipboard's memory directly? e.g. there is a BMP in the clipboard & i would like to read some bytes of that BMP directly from the memory without saving that BMP to harddrive nor pasting that BMP to a picturebox. I'm using VisualBasic
Who is Participating?
Option Explicit

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
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long

Private Sub Command1_Click()
    Dim b() As Byte
    Dim bmp As BITMAP
    Dim i As Long, BytesPerLine As Long

    Dim pic As StdPicture
    Set pic = Clipboard.GetData
    GetObject pic, Len(bmp), bmp
    BytesPerLine = (bmp.bmWidth * 3 + 3) And &HFFFFFFFC
    ReDim b(1 To BytesPerLine * bmp.bmHeight * 3) As Byte
    GetBitmapBits pic, UBound(b), b(1)  
    'All bitmap bytes are now in the array...
    For i = 1 To 100
        Debug.Print b(i)

End Sub
martymaneAuthor Commented:
EXCELLENT :) & so fast

1 last question though.
Is it possible to read those values (pixels) in memory using offsets & without assingning them to an array?
Just to make it faster
I've never tried it myself, but you can try the technique mentioned here:
martymaneAuthor Commented:
Great service!

Big THX Paul
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.