3 Replies Latest reply on Nov 24, 2011 9:37 AM by drkstr_1

    BitmapFill == Rubbish

    NilsTT

      Hello,

       

      I'm trying to do something rather simple but fail to do so as the BitmapFill seems to have very, very, very, limited capabilities.

       

      I want to fill a rectangle with an image (the reason for the rectangle is the Radius on the corners).

       

      Lets start with the short list: What works is:

       

      <s:Rect width="100%" height="100%" radiusX="10" radiusY="10">
           <s:fill>
                <s:BitmapFill source="@Embed('assets/160dpi/myImage.png')" />
           </s:fill>
      </s:Rect>
      

       

      The problem is that the image is defined for different dpi's so for the long list:

       

      What doesn't work is:

      - Setting the source for the BitmapFill to a MultiDPIBitmapSource (this I can understand)

      - Using a MultiDpiBitmapFill (as no such thing seems to exist)

      - Setting the source for the BitmapFill to an Image using DataBinding (So that I can have a var myImage:Image which is loaded from the correct source, dependent on dpi in the init phase)

      - Setting the source for the BitmapFill to a String using DataBinding (same as above but with a string, I admit this was a desparate attempt).

       

      Is there any solution or does the multi dpi model has met its limitations.

        • 1. Re: BitmapFill == Rubbish
          drkstr_1 Level 4

          Setting the source for the BitmapFill to an Image using DataBinding (So that I can have a var myImage:Image which is loaded from the correct source, dependent on dpi in the init phase)

          Don't set the source to an Image. Instead, assign the correct image as a Class, or load the Image and assign the BitmapData to the fill. It is possible to assign any DisplayObject to the source, but you need to make sure it is fully rendered before you do. An Image must perform other functions during the component lifecycle before it can renderer.

          • 2. Re: BitmapFill == Rubbish
            NilsTT Level 1

            Thanks alot,

             

            I have never seen any reason to load an image as a class but now I've found one.

             

            I do not understand your second solution

            ... or load the Image and assign the BitmapData to the fill...

             

            What Is the difference between this and what I've done

            • 3. Re: BitmapFill == Rubbish
              drkstr_1 Level 4

              The difference is that an Image component has nothing to display when you assign it to the BitmapFill. When you assign a DisplayObject as the source, the BitmapFill will take a snapshot of the pixels and convert it into a bitmap. For this to work, the Image must be fully loaded and rendered before you assign it as the source, otherwise there are no pixels to capture. It also seems a bit wasteful to get a bitmap snapshot of an Image component when you can reference the BitmapData directly.