Is it possible to copy the contents of a canvas to the clipboard?
Copy canvas to clipboard
BlitzPlus Forums/BlitzPlus Programming/Copy canvas to clipboard I asked the same question in the userlibs forum and haven't received a reply. It would sure be handy! In particular I'd like to move images to/from photoshop or other programs via the clipboard.
Try pressing CTRL & PrintScreen together. This will grab the whole window and all of the contents inside it (including a canvas if you have one).
Then you just load in your painting app and select paste.
I hope that helps
Then you just load in your painting app and select paste.
I hope that helps
Hi Prof,
Thanks for the reply but that is not what I was looking for. I'd like to be able to move the contents of a canvas to the clipboard within Blitz code and then bring it back again.
Thanks for the reply but that is not what I was looking for. I'd like to be able to move the contents of a canvas to the clipboard within Blitz code and then bring it back again.
can't you jut use the copyrect command to copy it to a new image then drawimage that when you want to paste it? You might have to do a rect with the current background colour on the area being copy to clear the space but it would work and is very simple.
Try this...
The code below copies a buffer to the clipboard.
Example
> Run the code below (after creating the userlibs file).
> Press a key to randomize canvas
> Choose Menu>Edit>Copy
> Open MSPAINT etc and paste!
NOTE: I have only implemented 'Image Copy' so far.
UserLibs needed
===============
The code below copies a buffer to the clipboard.
Example
CopyBuffer buffer,width,height
> Run the code below (after creating the userlibs file).
> Press a key to randomize canvas
> Choose Menu>Edit>Copy
> Open MSPAINT etc and paste!
NOTE: I have only implemented 'Image Copy' so far.
UserLibs needed
===============
.lib "user32.dll" OpenClipboard%(hwnd%):"OpenClipboard" CloseClipboard%():"CloseClipboard" EmptyClipboard%():"EmptyClipboard" SetClipboardImage%(format%,img%):"SetClipboardData" CBLoadImage%(Inst%,filename$,ImageType%,DesiredWidth%,DesiredHeight%,Flags%):"LoadImageA"
; Clipboard Image COPY/PASTE ; =========================== ; Syntax Error ; userlibs required ; ********************************************* ; .lib "user32.dll" ; OpenClipboard%(hwnd%):"OpenClipboard" ; CloseClipboard%():"CloseClipboard" ; EmptyClipboard%():"EmptyClipboard" ; SetClipboardImage%(format%,img%):"SetClipboardData" ; CBLoadImage%(Inst%,filename$,ImageType%,DesiredWidth%,DesiredHeight%,Flags%):"LoadImageA" ; ; ********************************************* Const w=400,h=300 ; image width & height Const title$="Clipboard Image Copy/Paste" AppTitle title$ win=CreateWindow(title$,50,50,w+8,h+24,Desktop(),8+4+1) Global can=CreateCanvas(0,0,w,h,win) menu=WindowMenu(win) editmenu=CreateMenu("Edit",0,menu) copy=CreateMenu("Copy (to clipboard)",1,editmenu) paste=CreateMenu("Paste (from clipboard)",2,editmenu) SetStatusText win,"press a key to draw new ovals" UpdateWindowMenu win SeedRnd MilliSecs() DrawOvals Repeat ev=WaitEvent() If ev=$103 If EventData()=27 Exit DrawOvals() EndIf If ev=$1001 ; menu If EventData()=1 ; copy CopyBuffer CanvasBuffer(can),w,h Notify "Copied to clipboard!" EndIf If EventData()=2 ; paste Notify "Not implemented yet :-<" EndIf EndIf Until ev=$803 End ;----------------------------------- Function CopyBuffer(buff,w%,h%) Local LR_LOADFROMFILE=$10 Local cf_BITMAP=2 Local filename$=SystemProperty$("tempdir")+"tmp.bmp" SaveBuffer buff,filename$ img=CBLoadImage(0,filename$, 0, w,h, LR_LOADFROMFILE) OpenClipboard 0 : EmptyClipboard SetClipboardImage cf_BITMAP,img CloseClipboard DeleteFile filename$ End Function ;----------------------------------- Function DrawOvals() SetBuffer CanvasBuffer(can) Cls For r=1 To 50 Color Rand(255),Rand(255),Rand(255) Oval Rand(0,w),Rand(0,h),Rand(5,50),Rand(5,50) Next FlipCanvas can End Function
Thaks Syntax that worked fine for what I needed.