So here is an example using the CopyImageToClipboard function.
This only creates 24-bit bitmaps.
This only creates 24-bit bitmaps.
;Copy Image to Clipboard function, by markcw on 28 Jul 06 Graphics3D 640,480,0,2 SetBuffer BackBuffer() image=LoadImage("yourname.bmp") ;load image width=ImageWidth(image) ;get image info height=ImageHeight(image) ok=CopyImageToClipboard(image) ;copy image to clipboard While Not KeyHit(1) Cls DrawImage image,50,50 ;draw the image Text 0,0,"OK, paste the current clipboard data to whatever" Text 0,12,"program you use to see the results of the image copy." Text 0,24,"image="+image+" width="+width+" height="+height+" ok="+ok Flip Wend Function CopyImageToClipboard(himage) ;Copy a given Blitz3D image to the clipboard ;From "Copying a DIB to the clipboard", by John Simmons ;(http://www.codeproject.com) Local width,height,sizeBits,sizeInfo,sizeDIB,btmp,x,y,offset,hDIB,pbmi width=ImageWidth(himage) height=ImageHeight(himage) ;calculate bits, DWORD-aligned scanline (Width * BitCount) * Height sizeBits=((width*24+31)/32*4)*height sizeInfo=40 ;sizeof(BITMAPINFOHEADER) sizeDIB=sizeInfo+sizeBits ;total size btmp=CreateBank(sizeDIB) ;bank to store DIB ;calculate DWORD-aligned offset of bits for proper alignment ;we'll use biSize to store each pixel, we can fill it in after LockBuffer(ImageBuffer(himage)) For y=0 To height-1 offset=((width*24+31)/32*4)*y+sizeInfo ;start of next scanline For x=0 To width-1 PokeInt btmp,0,ReadPixelFast(x,height-1-y,ImageBuffer(himage)) ;biSize PokeByte btmp,offset+(x*3),PeekByte(btmp,0) ;blue PokeByte btmp,offset+(x*3)+1,PeekByte(btmp,1) ;green PokeByte btmp,offset+(x*3)+2,PeekByte(btmp,2) ;red Next Next UnlockBuffer(ImageBuffer(himage)) ;fill in the info header for our 24-bit DIB PokeInt btmp,0,sizeInfo ;biSize PokeInt btmp,4,width ;biWidth PokeInt btmp,8,height ;biHeight PokeShort btmp,12,1 ;biPlanes, must be 1 PokeShort btmp,14,24 ;biBitCount PokeInt btmp,16,0 ;biCompression, RGB=0/RLE8=1/RLE4=2/BITFIELDS=3 PokeInt btmp,20,sizeBits ;biSizeImage, zeros here mean "default" PokeInt btmp,24,0 ;biXPelsPerMeter PokeInt btmp,28,0 ;biYPelsPerMeter PokeInt btmp,32,0 ;biClrUsed PokeInt btmp,36,0 ;biClrImportant ;alloc memory block to store our DIB hDIB=Api_GlobalAlloc(66,sizeDIB) ;GHND=66, MOVEABLE=2|ZEROINIT=64 If Not hDIB ;major bummer if we couldn't get memory block FreeBank btmp Return False ;fail code EndIf pbmi=Api_GlobalLock(hDIB) ;lock memory and get pointer to it Api_RtlCopyMemory(pbmi,btmp,sizeDIB) ;copy DIB to memory Api_GlobalUnlock(hDIB) ;unlock the DIB ;send the DIB to the clipboard If Api_OpenClipboard(0) ;hwnd Api_EmptyClipboard() ;free last data Api_SetClipboardData(8,hDIB) ;CF_DIB=8, hdata[bitmap] Api_CloseClipboard() EndIf FreeBank btmp Return True ;success code End Function