22 Replies Latest reply on Jun 9, 2008 9:24 AM by rafa@mediatech

    User imports image to .exe

    rafa@mediatech Level 1
      Hey everyone:
      I have a long going project where my client runs a .exe, fills in text boxes, hits "create", the .exe creates not pad files which are read by a separate .exe. When my client runs the 2nd.exe it reads from the notepads created by the 1st.exe

      I coded the 2nd.exe to look for images next to the root of the movie (or in a specific folder) , in this case, logos, that show up in a specific place of the 2nd.exe along with the information provided in the notepads.

      Is there a way i can create a "browse" button (just like you browse for the ICO file in the publish settings) in the 1st.exe, where my client can choose the image (logo) he wants to show on the 2nd.exe? Also, the space provided for the image on the 2nd.exe is not too big, can I make sure that if the image the user selects in the 1st.exe gets automatically shrunken down if it is larger than the area provided? Right now, I just told my client what pixel size he has to stay in so that it fits correctly, but it would be cool if the 2nd.exe shrinks the image if it larger than 150x250.

      Thanks everyone!!!
        • 1. Re: User imports image to .exe
          Level 7
          For the browse box, I would use BuddyAPI's baGetFilename() which will
          pull up that dialog box and tell you which file the user chose.

          To shrink the image into a given area, you just need to scale the .rect
          of the sprite and make sure you keep the aspect ratio the same as that
          of the original member.
          • 2. Re: User imports image to .exe
            rafa@mediatech Level 1
            Hi Mike:
            Thanks for the quick reply. Are there any tutorials or help documents on how to work with these properties you mentioned?
            • 3. Re: User imports image to .exe
              Level 7
              The help docs that come with BuddyAPI do a good job of explaining how to
              use it. And there isn't much to scaling a rect of a sprite...

              You can simply set the rect to go into a certain area, like

              sprite(1).rect=rect(0,0,100,100)

              Which will put it in a 100 x 100 box in the top corner. Or course you
              will want to get the aspect ratio of the image you are importing
              (member.height and member.width) and scale it proportionally.
              • 4. Re: User imports image to .exe
                rafa@mediatech Level 1
                Cool. I will play with it and post something here when I get it to work. Thanks for pointing me in the right direction Mike.
                • 5. Re: User imports image to .exe
                  rafa@mediatech Level 1
                  I was able to get an imported image to be re-sized to another size automatically. The question is, how can I make it retain proportions. The image I tested is portrait and the one I used as my safe area is landscape. This is the code I used:

                  on exitFrame me
                  sprite(2).rect = sprite(1).rect
                  end

                  I know it is way to simple, but what do I need to add so that sprite(2) re-sizes and keeps proportions?

                  Thanks!
                  • 6. Re: User imports image to .exe
                    Level 7
                    Here is a handler that will set an image to the appropriate size using
                    imaging lingo

                    http://www.mediamacros.com/item/item-1006687252/
                    • 7. Re: User imports image to .exe
                      rafa@mediatech Level 1
                      Mike:
                      Thanks for the link.
                      How and where would I use something like this? My previous code I was adding in a frame script. I think this would go on the member (place holder for member) it self?
                      • 8. Re: User imports image to .exe
                        Level 7
                        At any point after the program has brought in the image, run this line
                        of code:

                        rescale(member("YOURMEMBERNAME"),100,100)

                        Replace YOURMEMBERNAME with the name of the image member
                        Replace the 1st 100 with the max width
                        Replace the 2nd 100 with the max height
                        • 9. Re: User imports image to .exe
                          rafa@mediatech Level 1
                          I get a "Handler not defined" error. I think I am confusing where do I need to add the script from mediamacross.com and where to add "rescale(member("YOURMEMBERNAME"),100,100)"
                          • 10. Re: User imports image to .exe
                            rafa@mediatech Level 1
                            I got it. I figure out where the code needed to go.

                            Thanks Mike!
                            • 11. User imports image to .exe
                              rafa@mediatech Level 1
                              Ok...I got it work, but it only works once! It re-sizes the image when I run it the first time but...
                              If I run it again it gives me a prop error on the first line script line:
                              Script error: property not found
                              membRef.useAplha = FALSE...etc

                              I used the -- to ignore this line, but the it gives me the same error for the following line after that line...
                              • 12. Re: User imports image to .exe
                                Level 7
                                Above the line where the error occurs, put this

                                put membRef

                                What does that put in the message window?
                                • 13. Re: User imports image to .exe
                                  rafa@mediatech Level 1
                                  Well...it ignores it, and gives me the same error the second time around. Now, I see that:
                                  1.It works the first time I run it.
                                  2.If I run it again, and the image is already imported, then it gives me the error.

                                  When I run it the first time, for some reason the member's name is clear, the cast member shows no name, weird.
                                  • 14. Re: User imports image to .exe
                                    Level 7
                                    When you say it ignores it, do you mean that it does not put anything in
                                    the message window? If that is the case then you probably have the
                                    script in twice, and it is running the one that you did not add that
                                    line to... or something like that.

                                    If you added that line where I told you to, it should always put
                                    something in the message window, and the first time it is run, that
                                    something is what it needs.... the second time it is run, when it
                                    crashes, that something will be the incorrect value.
                                    • 15. Re: User imports image to .exe
                                      rafa@mediatech Level 1
                                      Mike:
                                      I apologize, I thought you meant the message window where I get the error. I place the code on the Window>message window and it gives me this:

                                      == Movie: C:\Documents and Settings\Rafa\Desktop\Director_resize image\re_size2.dir Frame: 1 Script: (member 0 of castLib 0) Handler:
                                      --> _movie.traceScript = 0

                                      other times it gives me this:
                                      -- (member 5 of castLib 1)

                                      Here is the code I am using, I do not believe I am adding anything twice (besides whatever was on the original line of code)

                                      • 16. Re: User imports image to .exe
                                        Level 7
                                        Instead of putting the whole rescale code in your frame script, make it
                                        a movie script. Remove all the on rescale.... stuff that you copied
                                        from mediamacros and make a new movie script. Make sure it is a movie
                                        script. Paste the handler in there.

                                        So you will have 2 scripts. One is a behaviour that looks like this:

                                        on exitframe me
                                        rescale(member("man walking"),100,100)
                                        end

                                        the other script is a movie script that is exactly what you have for the
                                        on rescale... handler

                                        Then, I think it will work as expected. I am working under the
                                        assumption that the original image in the score is "man walking" and the
                                        "MTPLogo" is the one that the user selected.
                                        • 17. Re: User imports image to .exe
                                          Level 7
                                          Also, you may not want to put that code on exitFrame. Unless it only
                                          appears on a single frame... If that script is running 15 times a
                                          second, and it is constantly rescaling the image, then it will slow your
                                          program down a lot. It is best to put the rescale line of code
                                          immediately after whantever code you have for bringing in the new image
                                          and setting the image on the stage. That way it only runs once and won't
                                          slow you down.
                                          • 18. Re: User imports image to .exe
                                            rafa@mediatech Level 1
                                            Mike:
                                            I made the changes you suggested. I added the rescale code on a movie script by itself. The image is shown on a single frame, I do not have multiple sections on the project where this image will show, only one. Now I get the error the first time I run it, but it does resize the image and then inmediatley gives me the error "Script error:Property not found
                                            membRef.useAlpha=FALSE--in director MX/winXP bmp's standard useAlpha=TRUE" when it reaches the "rescale(member("man walking"),100,100)" command.

                                            Now I tried placing the whole script on a movie script, including "rescale(member("man walking"),100,100)" and I don't get the error the first time I run it, only the second time around. I think it has something to do with the member's name being changed after it is rescaled, why do you think it changes the member's name?..well, it doesn't change it, it clears it, member has no name after it is rescaled.
                                            • 19. Re: User imports image to .exe
                                              Level 7
                                              This code is apparently meant to use the member number not name, so it
                                              is not properly renaming things after it does the conversion. Try this
                                              one instead which is edited slightly to make sure the name is the same.
                                              Put it in its own movie script and call it from your behaviour.

                                              on rescale membRef,maxW,maxH
                                              memName=membRef.name
                                              membRef.useAlpha=FALSE--in director MX/winXP bmp's standard
                                              useAlpha=TRUE
                                              wide=membRef.width
                                              high=membRef.height
                                              repeat while wide>maxW or high>maxH
                                              if wide>maxW then
                                              scaler=maxW/float(wide)
                                              wide=wide*scaler
                                              high=high*scaler
                                              nI=image(wide,high,16)
                                              nI.copyPixels(membRef.image,nI.rect,membRef.rect)
                                              membRef.erase()
                                              --k=new(#bitmap,membRef)
                                              --k.image=nI
                                              end if
                                              wide=membRef.width
                                              high=membRef.height
                                              if high>maxH then
                                              scaler=maxH/float(high)
                                              wide=wide*scaler
                                              high=high*scaler
                                              nI=image(wide,high,16)
                                              nI.copyPixels(membRef.image,nI.rect,membRef.rect)
                                              membRef.erase()
                                              --k=new(#bitmap,membRef)
                                              --k.image=nI
                                              end if
                                              k=new(#bitmap,membRef)--just one time
                                              k.name=memName
                                              k.image=nI
                                              wide=membRef.width
                                              high=membRef.height
                                              end repeat
                                              end
                                              • 20. Re: User imports image to .exe
                                                rafa@mediatech Level 1
                                                It works!
                                                The rescale code is in a movie script and the behavior is in a frame script.
                                                Why would the original code deal with member numbers? Wouldn't that make it harder to identify specific members? Or is it more advanced to work with members that way?
                                                • 21. Re: User imports image to .exe
                                                  Level 7
                                                  I didn't write the code, so I can't speak to why the author did things
                                                  the way they did... but it may just be that it was written for an older
                                                  version of Director. But what the script does save the image, delete
                                                  the member, then it makes a new member in the place where the old one
                                                  was and puts the scaled image into that. Perhaps not the way I would
                                                  have gone about it, but it works. Apart from the naming thing. If you
                                                  fed it the oldschool

                                                  member(3) of castlib 1

                                                  instead of

                                                  member("man walking")

                                                  then it would have worked as expected.
                                                  • 22. Re: User imports image to .exe
                                                    rafa@mediatech Level 1
                                                    Ok, so it just an older way of accomplishing the same thing. I guess I am spoiled, I started using Director with MX...

                                                    Mike, thanks for all your help ( and for all the other times you have helped me before.) This little feature makes my project a lot more user friendly.

                                                    THANKS!!!!