15 Replies Latest reply on Nov 9, 2010 7:54 AM by mattias72

    upload image with BuddyAPI

    Opera Rat
      I have a cast member as a place holder for a profile pic. I want the user to browse their computer for an image to use as their profile pic and then save that file to a specified location (the same location as the projector) and be the same size as the place holder image. My place holder image will be called image1.

      I think I have to use baGetFileName to get the file and save it. But it's not working. This needs to work on a mac and pc. Can someone give me some clues?
        • 1. Re: upload image with BuddyAPI
          Mouseclick Multimedia Level 1
          You won't be able to do that with just BuddyApi, you'll need the directImage-xtra too.

          http://www.directxtras.com/DImage_home.asp?UUID=2254686

          This will let you import any graphic file into your cast, resize it, crop it, recolor it or whatever and then export it to jpg or another format.

          In your topic title you state 'upload image'. If you want to upload it to a webserver, you'll need directFTP-xtra too, both are from the same company (see link above)

          hope this helps,

          Johan - Belgium
          • 2. Re: upload image with BuddyAPI
            Opera Rat Level 1
            I don't need to do all that. I didn't mean upload either, sorry. It's just selecting a jpg file on the harddrive. Saving that file with a fixed file name image1.jpg or something to the same directory as the movie. Then import that image into the move and use it on the stage. I don't want to crop, resize, or color it.
            • 3. Re: upload image with BuddyAPI
              Level 7
              Use baGetFilename() to let the user choose the file, then use
              baCopyFile() to copy it wherever you want.
              • 4. Re: upload image with BuddyAPI
                Mouseclick Multimedia Level 1
                Then I suppose you'll use 'importFileInto', with a combination of imagingLingo? Because else what will you do if the user selects a full resolution picture from a 12 megapixel camera? Just a thought...
                • 5. Re: upload image with BuddyAPI
                  Opera Rat Level 1
                  I'm half way there. I have the the browse to find the image on a drive working. It saves it as a cast member with the name image1 and that member image1 is used for a specific sprite (8). BUT resizing is now the issue. I have to figure out resizing to fit an area and keep the proportions correct. If the user chooses an enormous photo it will just look really bad - and that's ok. Let them choose another. The area is pretty large so even a large resolution should pass.

                  Right now after the file is selected it is placed in the area where it should be and is approximately the right size (proportions aside). But when the program runs again the image is its original size. I guess I somehow have to change the size of the image before it places it in the cast. And this is where I need help.

                  Script so far:

                  on mouseUp me

                  imagefilename = baGetFilename( "open", "c:\temp", "image1.jpg", "Images|*.jpg", -1, "Select Profile Photo", false, 100, 100 )

                  z=new(#bitmap, castLib("Internal"))
                  z=member("image1")
                  z.fileName=imagefilename
                  sprite(8).member=z

                  sprite(8).rect=rect(20,120,162,300)

                  end
                  • 6. Re: upload image with BuddyAPI
                    Opera Rat Level 1
                    The image rescaler on the mediamarcos site appears to be working for me. I just have to play with things a bit. I think I've got this.
                    • 7. Re: upload image with BuddyAPI
                      Opera Rat Level 1
                      NOT. Here are the 2 things that still need to happen. After the image is resized it needs to be saved in the cast with the member name image1. What ever the final proportions size is it needs have its top left corner placed with an x, y coordinate of 90, 180
                      • 8. Re: upload image with BuddyAPI
                        Level 7
                        on mouseUp me

                        imagefilename = baGetFilename( "open", "c:\temp", "*.jpg",
                        "Images|*.jpg",
                        -1, "Select Profile Photo", false, 100, 100 )

                        --z=new(#bitmap, castLib("Internal"))
                        z=member("image1")
                        z.fileName=imagefilename
                        rescale(member("image1"),140,300)

                        sprite(8).member=z

                        sprite(8).member.name="image1"
                        castlib("internal").save()

                        end
                        • 9. Re: upload image with BuddyAPI
                          Opera Rat Level 1
                          Thanks Mike. It works now, but the last thing is placing that image's top left corner in the same place no matter what the proportions end up being. right now it seems to place the lower left corner so there ends up being blank space above the image. I want the blank space below the image.
                          • 10. Re: upload image with BuddyAPI
                            Level 7
                            You can set the regPoint of the member after it is changed.

                            sprite(8).member.regPoint=point(0,0)

                            Put that just after you set it's name in the previous script...
                            • 11. Re: upload image with BuddyAPI
                              Opera Rat Level 1
                              YEAH!!!
                              • 12. Re: upload image with BuddyAPI
                                mattias72

                                I tried this code with buddyapi but why do I get this error code message:

                                 

                                Script Error: Property not found

                                 

                                z.fileName=imagefilename

                                 

                                 

                                 

                                -----------------------------------------------------------------------------

                                on mouseUp me
                                  
                                  imagefilename = baGetFilename( "open", "c:\temp", "image1.jpg", "Images|*.jpg", -1, "Select Profile Photo", false, 100, 100 )
                                  z=new(#bitmap, castLib("Internal"))
                                  z=member("image1")
                                  z.fileName=imagefilename
                                  rescale(member("image1"),140,300)
                                   
                                  sprite(8).member=z
                                 
                                  sprite(8).member.name="image1"
                                  castlib("internal").save()
                                   
                                end

                                • 13. Re: upload image with BuddyAPI
                                  Sean_Wilson Adobe Community Professional

                                  What do 'z' and 'imagefilename' hold when the relevant line of code runs? Try the following modification and report back what you see in your message window (Ctrl + M):

                                  on mouseUp me
                                    imagefilename = baGetFilename( "open", "", "", "Images|*.jpg", 4096 + 524288 + 4194304, "Select Profile Photo", false, 100, 100 )
                                    tMember = member("image1")
                                    put tMember, ilk(tMember), imagefilename
                                    tMember.fileName = imagefilename
                                    rescale(tMember, 140, 300)
                                    
                                    sprite(8).member = tMember
                                    
                                    castlib("internal").save()
                                  end
                                  

                                   

                                  The code relies on there being a cast member named "image1" in the internal castLib - perhaps that's why it fails for you?

                                  • 14. Re: upload image with BuddyAPI
                                    mattias72 Level 1

                                    The message i recieve is:

                                     

                                    -- (member 16 of castLib 1) #member "C:\Documents and Settings\familjen\Skrivbord\1.jpg"

                                     

                                    And script stopps and says:

                                     

                                    Script error: Handler not defined

                                    rescale(tMember, 140, 300)

                                    #rescale

                                     

                                    But problem is solved it works when I remove  "rescale(tMember, 140, 300)"

                                    I do wanna rescale the member ... since it dint work i changed the width and height of the sprite instead

                                     

                                    The reason it didnt work before it is a director error/bugg because the script works sometimes and sometimes not

                                    But it always work when I make a projector of the file and put the buddy api in a duplicate xtras folder in the same place

                                    as the projector

                                     

                                    ------------------------------------------------------------------------------------------ -----------------------------------------

                                    Though I have another problem

                                     

                                    --use this to opem wordpad I put it in frame 1

                                    baOpenFile( "C:\Program\Windows NT\Tillbehör\wordpad.exe" , "active" )

                                     

                                    --this I put in frame 15 to put the text in the wordpad

                                    On BeginSprite
                                      baSendKeys( "Some example text of interest" )
                                    end

                                     

                                    Well this works! But the wordpad is open all the time and it open up new wordpad every time I

                                    use the script.

                                     

                                    So i tried this instead in frame 1:

                                     

                                    baSetWindowDepth( baWinHandle() , 3 )

                                     

                                    --it puts the director movie behind wordpad

                                    But since wordpad aint active the text "Some example text of interest" wont show

                                    • 15. Re: upload image with BuddyAPI
                                      mattias72 Level 1

                                      I made it with help of other groups:

                                      though it aint so pretty the last lines but it sure works

                                       

                                      --frame1

                                      on exitframe
                                       
                                        MyWindowTitle = "Dokument - WordPad"
                                        MyWindowHandler = VOID
                                       
                                        WindowList = baWindowList("","",FALSE)
                                        repeat with i=1 to WindowList.count
                                          -- in fact, most likely, your recent window is among the first 30.
                                          -- but remember, it does not open immediatly. You need to put this script in
                                          --    an exitframe, so
                                          -- it can enter and exit until the window is open and recognized.
                                         
                                          if baWindowInfo(WindowList[i],"title") contains MyWindowTitle then
                                            MyWindowHandler = WindowList[i]
                                            exit repeat
                                          end if
                                        end repeat
                                       
                                        if MyWindowHandler = VOID then
                                          go to the frame
                                          abort
                                        else
                                          --In the same exitframe, once MyWindowHandler is not VOID, you know that it
                                          --    is open, and it is the window with focus.
                                          --Now you can try :

                                      baWindowToBack( baWinHandle() )
                                         
                                         
                                         
                                         
                                          --And
                                          go to the frame +1
                                          abort
                                        end

                                       

                                       

                                      --frame 10

                                       

                                      On BeginSprite
                                        baPlaceCursor( 300 , 400 )
                                        baMouseClick( "left" )
                                      end

                                       

                                       

                                      --frame15

                                      On BeginSprite
                                           baSendKeys( "Text " )  
                                         end

                                       

                                      on exitFrame me
                                         go to the frame
                                      end