Announcement

Collapse
No announcement yet.

Drag n drop with Images

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Drag n drop with Images

    Hi all
    Can anyone help with drag n drop with images its confusing me and getting frustrated. I have tried a few examples but not what I want.
    e.g.
    I have two images, “Image1 and Image2”. I would like to drag an image from a Desktop folder, into Image1 and drag n drop a different Image into Image2

    Can anyone point me in the right direction to do this.

  • #2
    I dont think this is available in AMS , But if it is exist by AMS or a plugin then this will be amazing. Hope the Experts here help you.

    Comment


    • #3
      Originally posted by MrBryza View Post
      Hi all
      I have tried a few examples but not what I want...
      ... I would like to drag an image from a Desktop folder ...
      Yes, there are a number of 'image drag-n-drop' examples floating around which can be found via simple forum searching. However, I can not recall ever seeing one which demonstrates dragging from desktop. All the examples I've seen, demonstrate dragging from within the app's GUI only

      Comment


      • #4
        The attached example should get you started. It requires the MemoryEx plugin, which you can get from https://www.memoryex.net/mx.html

        Look at the On Show, On Close and Globals code sections.
        Attached Files
        Bas Groothedde
        Imagine Programming :: Blog

        AMS8 Plugins
        IMXLH Compiler

        Comment


        • #5
          Far out, IP - that's awesome! You're not going to give me an aneurysm with this one, sensei - I can follow your code this time (well, sort of).

          @MrBryza,
          If you replace IP's Listbox with an Image object, and then substitute the following line to his code in the Page On Show event, you'll be able to drag images from desktop, so they display in said Image object:
          Code:
          DragAndDrop.AcceptOnWindow(Application.GetWndHandle(), function(files)
             [COLOR=#008000][I] -- ListBox.DeleteItem("ListBox1", -1);[/I][/COLOR]
              
              for i, v in pairs(files) do 
                  [I][COLOR=#008000]-- ListBox.AddItem("ListBox1", v);[/COLOR][/I]
                 [COLOR=#FF0000] Image.Load("Image1", v);[/COLOR]
              end 
          end);
          Above will display same image in any given number of Image objects. Is a work in progress - am still trying to get my head around the rest of IP's code. LOL, you always challenge me to think, sensei!

          Comment


          • #6
            Nice BioHazard The files parameter is a table of files that have been dropped, so that multiple files can be dropped. To select two of these, you could access files[1] and files[2].
            Bas Groothedde
            Imagine Programming :: Blog

            AMS8 Plugins
            IMXLH Compiler

            Comment


            • #7
              Hi guys,
              Here's another example that I've worked on using action drag drop plugin
              DDTest.apz
              DragAndDrop.zip
              Cheers

              Comment


              • #8
                Thanks for the example Imagine.

                Below is an example I found for drag n drop images from desktop or folders. I have modified it but the coding isn't correct.

                With this example, I have two images Top_Image and Bottom_Image, but when I drag an image from my desktop, it fills in Image 1, and also shows in Image 2.
                I can see why it does this but I don't know to fix.

                I would like to drag an image into Top_Image and Drag a different image into Bottom_Image.

                You will see what I mean if you download the example.

                Comment


                • #9
                  Thanks Colc I have seen those examples also.

                  Comment


                  • #10
                    Here is the apz
                    Attached Files

                    Comment


                    • #11
                      hi MrBryza did you try my ddtest.apz?
                      it sets a true variable to allow image1 then image2 then image1 etc

                      Comment


                      • #12
                        colc Thank you just what I wanted.
                        Much appreciated
                        Thanks.

                        Comment


                        • #13
                          For the needs you've outlined above, there's a fair bit of superfluous coding in colc's example. No offence intended there, glebe0id! But we do have to keep you 'westie hoodrats' in line from time to time. .

                          We can simplify things somewhat, by deleting the Input box and re-expressing the code in the On Timer event, like such:
                          Code:
                          tData = DragAndDrop.GetDataObject();
                          
                          for k,v in pairs(tData) do
                              
                              local t = String.SplitPath(v);
                                  
                                  sDrive = t.Drive;
                                  sFolder = t.Folder;
                                  sFile = t.Filename;
                                  sExt = t.Extension;
                                  
                              local s = sDrive..sFolder..sFile..sExt;
                                      
                              if sExt == ".png" or sExt == ".jpg" or sExt == ".bmp" then
                                  
                                  if not loaded then
                                      Image.Load("Image1", s);
                                      loaded = true                
                                  
                                  elseif loaded then
                                      Image.Load("Image2", s);
                                      loaded = false            
                                  end
                              end
                          end
                          Haven't quite been able to figure out why exactly it's necessary to split the filepath string on Line-5 (into a table as its constituent filepath parts), only to then concatenate it back into a filepath string again on Line-12. Seems extraneous - but is apparently (for some weird reason) necessary. (Never mind, is probably just me, having a Homer Simpson moment, again. LOL).

                          Also, the boolean ("loaded", nee "iset") switch down the bottom is problematic - in that it will get confused when trying to load an image when both image-objects are already loaded. Haven't ironed out that little technicality, yet. Am too tired, so my cerebral logic chip is malfunctioning.
                          Attached Files

                          Comment


                          • #14
                            Update:
                            Just expanded the range of accepted image formats a little. (Add in whichever formats you want):
                            Code:
                            tData = DragAndDrop.GetDataObject();
                            
                            for k,v in pairs(tData) do
                                
                                local t = String.SplitPath(v);
                                    
                                    sDrive = t.Drive;
                                    sFolder = t.Folder;
                                    sFile = t.Filename;
                                    sExt = t.Extension;
                                    
                                local s = sDrive..sFolder..sFile..sExt;
                                
                                local e = {
                                    ".png",
                                    ".jpg",
                                    ".bmp",
                                    ".gif",
                                    ".tif"
                                };
                                        
                                for k,v in pairs (e) do
                                    if sExt == v then
                                    
                                        if not loaded then
                                            Image.Load("Image1", s);
                                            loaded = true                
                                    
                                        elseif loaded then
                                            Image.Load("Image2", s);
                                            loaded = false            
                                        end
                                    end
                                end
                            end

                            Comment


                            • #15
                              What if the i want to drag the picture to Image1 for 3 or more times without going the picture to Image2?
                              Only will go the picture to image2 if the user want it to drop on the Image2..

                              i there a way we can get which image is in hover the mouse since the app is not active?

                              Comment

                              Working...
                              X