Quote: "This should do what you need."
Yes That works. I just added the Width, and Height to it. I found that I had to make the image twice, else set display mode deletes it.
#constant _USER32 1
#constant _TRUE 1
#constant _FALSE 0
load dll "user32.dll", _USER32
do
if CheckClipboardImage()=_TRUE
result=GetClipboardImage(1)
if result=_TRUE
make image from memblock 1,1
set display mode image width(1), image height(1), 32
make image from memblock 1,1
paste image 1,0,0
wait key
end
endif
endif
loop
Function CheckClipboardImage()
`*************************************************************************************************************************************************************************************************************************************
`Checks if an image is available on the clipboard. Returns _TRUE for yes, _FALSE for no
result=call dll(_USER32,"OpenClipboard",0) `Try opening clipboard (0=For this process)
if result=0 then ExitFunction _FALSE `If can't open clipboard then immediate exit with failure
local handle as dword
handle=call dll(_USER32,"GetClipboardData",_CF_DIBV5) `Try get handle to clipboard object in requested format
call dll _USER32,"CloseClipboard" `Close clipboard for this process (Ignore resultcode even if error)
if handle>0 then ExitFunction _TRUE `Found a valid image - return TRUE
EndFunction _FALSE
Function GetClipboardImage(memblk)
`*************************************************************************************************************************************************************************************************************************************
`Gets an image from the clipboard and stores it as a memblock image structure in the specified memblock
`Returns 1 if successful, 0 if not. (eg. no image, not compatible, compressed etc)
`BITMAPV5HEADER Structure - see http://msdn.microsoft.com/en-us/library/dd183381%28VS.85%29.aspx
`memblk Number of the memblock to use for image (Must not already exist)
#constant _CF_BITMAP 2 `Types of bitmap structure for clipboard
#constant _CF_DIBV5 17 `This is preferred format
result=call dll(_USER32,"OpenClipboard",0) `Try opening clipboard (0=For this process)
if result=0 then ExitFunction _FALSE `If can't open clipboard then immediate exit with failure
local handle as dword
handle=call dll(_USER32,"GetClipboardData",_CF_DIBV5) `Try get handle to clipboard object in requested format
if handle>0
bV5Size =peek dword(handle) `Size of BitmapV5 structure
bV5Width =peek dword(handle+4) `Pixel width of image
bV5Height =peek dword(handle+8) `and height
bV5BitCount=peek word(handle+14) `Get bits depth from structure (Can only copy 24 or 32bit images)
bV5Compress=peek dword(handle+16) `Compression mode, 0 or 3=uncompressed
if (bV5BitCount=24 or bV5BitCount=32) and (bV5Compress=0 or bV5Compress=3)
make memblock memBlk,(bV5Width*bV5Height*4)+12 `Make a memblock to fit destination image
dPtr=get memblock ptr(memBlk) `Dest pointer
poke dword dPtr ,bV5Width `Memblock image width
poke dword dPtr+4,bV5Height `and height
poke dword dPtr+8,32 `depth always 32bit
inc dPtr,12 `Set dest pointer to start position for pixel data
byteCount=bV5BitCount/8 `Calc bytes per pixel used in source img
pad=4-((bV5Width*byteCount) mod 4) `Padding to keep source bitmap each line on 32bit boundary
if pad=4 then pad=0
for y=bV5Height-1 to 0 step -1
sPtr=handle+bV5Size+(bV5Width*y*byteCount)+(y*pad) `Calc source bitmap pointer for each line
for x=0 to bV5Width-1
poke dword dPtr,peek dword(sPtr) `Copy each pixel from source to dest memblock
inc dPtr,4 `Inc dest ptr (Should really check/clear spare byte in dest but works without doing it?)
inc sPtr,byteCount `Inc source pointer by bytes per pixel (3 or 4)
next x
next y
call dll _USER32,"CloseClipboard" `Close clipboard for this process (Ignore resultcode even if error)
ExitFunction _TRUE `Completed successfully - return TRUE
endif
endif
call dll _USER32,"CloseClipboard" `Close clipboard for this process (Ignore resultcode even if error)
EndFunction _FALSE
