• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • Last Modified:

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
0
martymane
Asked:
martymane
  • 2
  • 2
1 Solution
 
PaulHewsCommented:
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)
    Next


   
End Sub
0
 
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
0
 
PaulHewsCommented:
I've never tried it myself, but you can try the technique mentioned here:
http://www.visualbasicforum.com/t25347.html
0
 
martymaneAuthor Commented:
Great service!

Big THX Paul
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now