Can I copy (or drag/drop) a Canvas.Backdrop (jpeg) back to the desktop as a JPEG?
Thanks
yes but you have to write some method(s) for that.
And in nearly 20 years, I never was able to do that.
Thanks for replying…
I was able to get a simple soultion to meet my needs…
Dim pic As New Picture(Canvas1.Width, Canvas1.Height, 32)
Canvas1.Drawinto( pic.Graphics,0,0 )
pic.Save(oFolder, Picture.SaveAsjpeg)
Jim
If it is just the Backdrop property you want to save you can write simply…
Canvas1.Backdrop.Save( oFolder, Picture.SaveAsjpeg )
So, no drag and drop ?
(or I misunderstand your answer)
I don’t use drag-drop very often. Fiddling around I found this to work but maybe there’s a better practice.
This doesn’t start a drag until you’ve dragged 10 points worth on the canvas.
To drop a file on the Desktop the DragItems Folderitem property needs to be set, which means you need to have made the file first, before dragging. If the user doesn’t complete the drop then the file is left where it was created, otherwise the file is basically moved and has the original name.
A complication is knowing if a drop succeeded, and in deleting an undropped file. To know if it moved I compare the URLPath before and after. Doing the compare and delete just after drag.Drag in MouseDrag caused problems, seems the OS doesn’t move the file till after MouseDrag finishes. So instead a Timer is started that does the check.
[code]//Properties
downX As Integer
downY As Integer
hasntDragged As boolean
fileBeingDragDropped As FolderItem
undroppedPath As String
//Canvas1 events
Function MouseDown(X As Integer, Y As Integer) As Boolean
downX = X
downY = Y
hasntDragged = true
return true
End Function
Sub MouseDrag(X As Integer, Y As Integer)
if hasntDragged and ( Abs(X-downX) > 10 or Abs(Y-downY) > 10 ) then
hasntDragged = false //prevent any further MouseDrags from triggering a drag
fileBeingDragDropped = SpecialFolder.Temporary.Child("droppedFileName.jpg") //get temp file
undroppedPath = fileBeingDragDropped.URLPath //and store it's initial path
dim pic As Picture = me.Backdrop //get picture
pic.Save(fileBeingDragDropped, Picture.SaveAsJPEG, Picture.QualityHigh) //write picture file
dim drag As new DragItem( me, 0, 0, pic.Width, pic.Height, pic ) //create dragitem
drag.FolderItem = fileBeingDragDropped //set file to drag
drag.Drag //initiate dragging
postDropTimer.Mode = Timer.ModeSingle //start timer to check for move
end
End Sub
//postDropTimer, Period = 1000, initial Mode = OFF
Sub Action()
if fileBeingDragDropped <> nil then
if fileBeingDragDropped.URLPath = undroppedPath then //didn’t move
fileBeingDragDropped.Delete
end
else
//err, no file ref
end
fileBeingDragDropped = nil
End Sub[/code]
Also, this uses pic.Width and pic.Height in creating the DragItem but with HiDPI it might be more appropriate to use pic.Graphics.Width/Height for point size.
On mac it’s better to use promised files where you only save the file if it was dropped. At least that’s my understanding, never used. The docs for DragItem mention this but only explain for accepting drops, not dropping to the Finder, and I couldn’t figure it out.
Also, in the docs for DragItem.Destination it says
So maybe even my code only works on mac !?
Drag Text to the Finder (I suppose it is the same with the Explorer and on Linux) is handled (by Xojo / the OS) when the drag comes from TextArea / TextField. Drag text (Rows) from a Listbox is a bit less easy, but doable.
I use heavilly drag and drop on OS X, but since Windows works far differently than OS X, I have to be careful when doing drag and drop on Windows.
D‘n’D with images files to a Xojo application window ie easy, doing so from a Xojo application window to Finder / Explorer / Linux… I stop trying years ago.
Did you try my code? That’s what it’s supposed to do but I can only test mac.
Not yet.
I have a MacBook Pro and a WIndows 10 laptop. I will try as soon as possible and report.
Will:
I build a brand new project (2015r1) and checked it: it works fine !
I added drag and drop FROM the Finder INTO the WindowÂ’s Canvas, and then, I added your code.
Not a single error detected.
El Capitan.
Now IÂ’m goind to the Windows 10 laptop (no, not to the blackboardÂ… French joke)
Will: I do not know if youÂ’re a genius, butÂ…
Testing OK. WIndows 10 / Xojo 2016r3, running in the IDE:
Drag and drop FROM the Explorer INTO the WindowÂ’s Canvas: OK, image displayed.
Drag and drop FROM the WindowÂ’s Canvas INTO the Explorer : OK, image file in the target folder.
Not a single error detected.
THANK YOU !
Now I can reinsert my TV Stick and continue to watch TV while coding with Xojo.
I also have to set my license BACK on OS X.