2 Replies Latest reply on Nov 10, 2008 7:09 AM by skider

    Problem with image scaling

    skider Level 1
      I'm currently writing a flex application where I'm scaling images on a hidden canvas, and then taking a bitmap of them and drawing that bitmap to a visible component. There are two reasons for this: so that the user doesn't see a mixture of scaled and unscaled images, and so that I can do some operations on the bitmap, saving the processing time of altering all of the objects.

      The problem is that the scaling doesn't seem to have finished by the time I create the bitmap. Is there a way that I can be sure the operation has finished first? Or is there a better way I should be going about this?
        • 1. Re: Problem with image scaling
          m_hartnett Level 3
          You could try adding an event listener for the scaled image. Take a look at some of the events for an Image such as the complete, updateComplete, resize or valueCommit. Call the build of your bitmap from the event responder method.

          I am not sure which event(s) get executed after a scale but it may be one of the events mentioned above.
          • 2. Problem with image scaling
            skider Level 1
            Although I didn't see an event for scaleX and scaleY, width and height do have an associated event (ResizeEvent), so I decided to use them for my scaling. I set up an event listener, and counted the events that had been fired, until they had been fired for each of the items that was to be scaled.

            I checked to see whether it worked, and it seemed not to have. In fact, it seems to have given me the same result as I had without the event listener, so as far as I can tell, the event is being called at the beginning of the resize rather than when it is completed.

            The problem isn't due to bad placement or sizing logic, as I've tested making the buffer visible, and it responds as expected, albeit with the resize flicker that I'm trying to eliminate. I am also certain that the draw is being triggered in the event listener, and have tested to make sure that there are no further resize events that I am not handling.

            I'm honestly kind of baffled. How can I resize multiple interconnected pieces of content without a separation being visible to the user in the intervening frames?

            Edit: I was able to tell when the image loaded by attaching a listener to the image that listened for the update event. I may be coming at this from the wrong angle, though, so I'm going to look into other ways to solve this problem as a whole.