5 Replies Latest reply on Nov 6, 2006 11:52 AM by Newsgroup_User

    scaling an image

    Level 7
      I've just been told (in the above thread) about how to link a local file
      to a web image.

      After I've imported that external image (while the movie is playing) I
      want to scale it in proportion to fit in a box defined on screen. Is
      that relatively easy?

      Thanks.

        • 1. Re: scaling an image
          Level 7
          Hi Student!

          Should not be to hard, to scale a sprite within certain limits:

          determine size of castmember
          devide targetWidth by castmemberWidth
          devide targetHeigh by castmemberHeight

          (whichever result is smallest is leading (the scalefactor), whatch out
          for Director's automatic rounding! cast castmemberWidth and
          castmemberHeight to a float-type variable with the float() function for
          instance)

          then you know what the scalefactor which is needed to scale down to the
          desired dimensions. Multiply both width and height by the scalefactor
          and you're done.

          Whatch it though, when the scalefactor is greater than 1, the image was
          actually smaller than the desired dimension. You will be upscaling in
          that case.

          Not really sure if this is the fastest way. You could try and do it with
          imaging lingo as well, doubt it'll be faster.
          Not sure either if it's wise to convert the width and height values you
          calculated back to integers before actually scaling the sprite. Works if
          you don't though.

          Manno

          uni-student wrote:
          > I've just been told (in the above thread) about how to link a local file
          > to a web image.
          >
          > After I've imported that external image (while the movie is playing) I
          > want to scale it in proportion to fit in a box defined on screen. Is
          > that relatively easy?
          >
          > Thanks.
          >

          --
          ----------
          Manno Bult
          manno@xs4all.nl
          • 2. Re: scaling an image
            Level 7

            Hi Manno - Thanks again, for this reply and the one above. I haven't got to
            test them out as was doing a few other things but think I understand what I
            need to do.

            I actually discovered a good behavior resource at Mediamacros.com.Over there,
            there's even a 'scale image' custom message.
            http://www.mediamacros.com/item/item-960841341/
            It's in the format: rescale (member , max width, max height)

            I tested it using:
            rescale (member("myImage"), 300, 400)
            and it did it perfectly.

            • 3. Re: scaling an image
              Level 7
              Hi there,

              If that script works, you're done :)

              I just wonder, (Dave, you there?) why the loop?

              Manno

              uni-student wrote:
              > Hi Manno - Thanks again, for this reply and the one above. I haven't got to
              > test them out as was doing a few other things but think I understand what I
              > need to do.
              >
              > I actually discovered a good behavior resource at Mediamacros.com.Over there,
              > there's even a 'scale image' custom message.
              > http://www.mediamacros.com/item/item-960841341/
              > It's in the format: rescale (member , max width, max height)
              >
              > I tested it using:
              > rescale (member("myImage"), 300, 400)
              > and it did it perfectly.
              >

              --
              ----------
              Manno Bult
              manno@xs4all.nl
              • 4. Re: scaling an image
                Level 7
                >>Why the loop?

                Heh.

                No idea. Not sure what I was thinking with that. I just made this one:

                on rescale mRef, maxWide, maxHigh
                oWide = mRef.width
                oHigh = mRef.height
                useRatio = max(maxWide / float(oWide), maxHigh / float(oHigh))
                ni = image(oWide * useRatio, oHigh * useRatio, 32)
                ni.copyPixels(mRef.image, ni.rect, mRef.rect)
                return ni
                end


                This works just as well, and is a wee shorter. <g> It also returns a new
                image, instead of modifying the original. Also, since it keeps the aspect
                ratio, I like to typically pass in 0 for one of the arguments so that you
                know how the resizing will happen.

                For instance, if my original is 744 x 178 and I want to resize it so the
                width is 100:

                member(new(#bitmap)).image = rescale(member("fullSize"), 100, 0)

                The new image will be 100 x 24

                Or, if you know you wanted the height to be 24:

                member(new(#bitmap)).image = rescale(member("fullSize"), 0, 24)




                --
                Dave -
                Head Developer
                www.blurredistinction.com
                Adobe Community Expert
                http://www.adobe.com/communities/experts/


                • 5. Re: scaling an image
                  Level 7


                  DMennenoh **AdobeCommunityExpert** wrote:
                  >>> Why the loop?
                  >
                  > Heh.

                  Always nice to look at your own old code ;)


                  --
                  ----------
                  Manno Bult
                  manno@xs4all.nl