Drag&Drop image from a browser
Drag&Drop image from a browser
Drag&Drop can be used in most browsers to easily copy an image from the webpage to a folder. You can also drag an image to an application (for example when dragged into the purebasic editor the URL is pasted). I've tried and tried, but I can't get this behaviour to work in my PureBasic programs. What's the difference between dragging a file from the desktop, or dragging a file from a browser?
I've tested File, Image and Text formats with Chrome and Firefox.
I've tested File, Image and Text formats with Chrome and Firefox.
~Rudolf Enberg
Re: Drag&Drop image from a browser
Hi,
I tested it with this codeit works.
I can drag and drop a picture from my browser.
To test it, simply drag the 'New topic' button on the picture of the PB program and drop it.
The main thing is:
You have to know what you want to drag and drop: a file or a picture.
You can not drag a file on a picture.
when you don't want to show the droped picture, simply remove the SetGadgetState()
and replace it with a SaveFileRequester().
Bernd
I tested it with this code
Code: Select all
CreateImage(0, 310, 200)
OpenWindow(0, 0, 0, 330, 220, "Drag'n drop test", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
ImageGadget(0, 10, 10, 310, 200, ImageID(0))
EnableGadgetDrop(0, #PB_Drop_Image, #PB_Drag_Move|#PB_Drag_Copy)
Exit = #False
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_GadgetDrop
If EventDropType() = #PB_Drop_Image
If EventDropImage(0)
SetGadgetState(0, ImageID(0))
EndIf
EndIf
Case #PB_Event_CloseWindow
Exit = #True
EndSelect
Until Exit
I can drag and drop a picture from my browser.
To test it, simply drag the 'New topic' button on the picture of the PB program and drop it.
The main thing is:
You have to know what you want to drag and drop: a file or a picture.
You can not drag a file on a picture.
when you don't want to show the droped picture, simply remove the SetGadgetState()
and replace it with a SaveFileRequester().
Bernd
Re: Drag&Drop image from a browser
Hi,
here an example to save the file imediatelyBernd
here an example to save the file imediately
Code: Select all
UseJPEGImageEncoder()
OpenWindow(0, 0, 0, 330, 220, "Drag'n drop test", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
ExplorerTreeGadget(0, 10, 10, 310, 200, "")
EnableGadgetDrop(0, #PB_Drop_Image, #PB_Drag_Move|#PB_Drag_Copy)
Exit = #False
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_GadgetDrop
If EventDropType() = #PB_Drop_Image
Picture = EventDropImage(#PB_Any)
If Picture
Filename$ = GetGadgetText(0) + "\drop.jpg"
SaveImage(Picture, FileName$, #PB_ImagePlugin_JPEG)
EndIf
EndIf
Case #PB_Event_CloseWindow
Exit = #True
EndSelect
Until Exit
Re: Drag&Drop image from a browser
Thanks for the help, but neither example worked for me. Drag&drop was not enabled at all. What might be wrong on my end?
Last edited by Ruuttu on Tue Aug 30, 2011 1:45 pm, edited 2 times in total.
~Rudolf Enberg
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Drag&Drop image from a browser
infratec's code working fine on my PC, WinXP 32bit, any compiler settings, PB4.51.
edit: I should say that both methods work (extremely well I might add).
edit: I should say that both methods work (extremely well I might add).
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Drag&Drop image from a browser
I did some further testing and it worked great on another PC with 32-bit Windows 7. It fails on my 64-bit Windows 7 - is this the problem?
~Rudolf Enberg
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Drag&Drop image from a browser
Hmm, I do not know enough to be definitive but sounds like that is the problem - when you drag the image, it may be 'stored' in memory as a 64bit file, which would then make it incompatible with the 32bit PB app? Sounds logical..........quick test would be to compile the code as 64bit.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Drag&Drop image from a browser
Oh, cool. So a 64-bit-compiled version must be used on a 64-bit system. That's a shame, I'll probably be forced to make two versions of the program. I'm sure there's a way around it though, for example 32-bit winRAR manages to do drag&drop on my 64-bit system.
~Rudolf Enberg
-
- Addict
- Posts: 1675
- Joined: Sun Dec 12, 2010 12:36 am
- Location: Somewhere in the midwest
- Contact:
Re: Drag&Drop image from a browser
Both examples work on my system.
Windows 7 x64
Purebasic 32bit
a 32 bit application will run on a 32 or 64 bit OS
a 64 bit compiled application must be run on a 64 bit OS
Unless you need something special that 64 bit offers (certain instructions, or access to more memory, etc) then just stick with 32bit Purebasic, compiling 32 bit apps.
If the program is running in 32bit, then it is allocating memory in 32bit space, and cannot use/access 64 bit allocated memory, (although I think it is possible to do this if you do some trickery, Crysis 2 supposedly does this even though its 32bit)
But then again, I could be talking out of my ass too. I have a feeling I'm close to the mark though. Are you sure you attempted the D&D properly on your x64 PC? Anything special setup that might be interfering with it?
You could try running it in debug mode, or step-through execution.. But if this were a 32/64bit problem I do not think the application would start at all, or at the least would crash with an error message once you attempted to do something.
Windows 7 x64
Purebasic 32bit
a 32 bit application will run on a 32 or 64 bit OS
a 64 bit compiled application must be run on a 64 bit OS
Unless you need something special that 64 bit offers (certain instructions, or access to more memory, etc) then just stick with 32bit Purebasic, compiling 32 bit apps.
If the program is running in 32bit, then it is allocating memory in 32bit space, and cannot use/access 64 bit allocated memory, (although I think it is possible to do this if you do some trickery, Crysis 2 supposedly does this even though its 32bit)
But then again, I could be talking out of my ass too. I have a feeling I'm close to the mark though. Are you sure you attempted the D&D properly on your x64 PC? Anything special setup that might be interfering with it?
You could try running it in debug mode, or step-through execution.. But if this were a 32/64bit problem I do not think the application would start at all, or at the least would crash with an error message once you attempted to do something.
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Drag&Drop image from a browser
...I could be horribly wrong but it does seem that the images are 64bit, which therefore would not work in a 32bit app unless the app was designed specifically to accommodate them. Similar perhaps to storing a 64bit app on a 32bit OS - the 32bit OS cannot display the icon/thumbnail of the 64bit file.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Drag&Drop image from a browser
Well, I tested and I can't drag files either. I got text working but it only works when dragging text from another 32-bit application. I don't think it's a limitation of Windows, as I've seen loads of other applications that can receive all sorts of drop events running in 32 bits on a 64-bit OS. I don't really know enough about this to say anything definite, but I know I'm gonna have to ship two versions of the program for now.
~Rudolf Enberg
-
- Addict
- Posts: 1675
- Joined: Sun Dec 12, 2010 12:36 am
- Location: Somewhere in the midwest
- Contact:
Re: Drag&Drop image from a browser
I've thought about it and its probably correct.
Without some magic kung-fu D&D probably would be limited between 32 bit programs only..
I don't think it will be that hard on you though. Hopefully you should be able to maintain separate installations of PureBasic (just use the /PORTABLE switch on the shortcut to the EXE and all settings will stay in their own directory)
May want to keep two copies of the program source, just to be safe. Or you can compile the 32bit, then close out, and reopen the project in 64bit and compile your x64 version.
Hopefully it would require no modification to the code at all, I would like to think.
Windows 7x64 should have both a 32 & 64 bit Internet Explorer, so I guess one definitive test would be to see if you can D&D from one version, but not the other.
Google seems to indicate it is just not possible to D&D between a 32 & 64 bit program (also admin/non-admin processes)
Without some magic kung-fu D&D probably would be limited between 32 bit programs only..
I don't think it will be that hard on you though. Hopefully you should be able to maintain separate installations of PureBasic (just use the /PORTABLE switch on the shortcut to the EXE and all settings will stay in their own directory)
May want to keep two copies of the program source, just to be safe. Or you can compile the 32bit, then close out, and reopen the project in 64bit and compile your x64 version.
Hopefully it would require no modification to the code at all, I would like to think.
Windows 7x64 should have both a 32 & 64 bit Internet Explorer, so I guess one definitive test would be to see if you can D&D from one version, but not the other.
Google seems to indicate it is just not possible to D&D between a 32 & 64 bit program (also admin/non-admin processes)