3 Replies Latest reply on Apr 9, 2010 9:15 AM by David_F57

    How to preserve aspect ration of image in s:BitmapImage?

    MarkTaylor46 Level 2

      Hi, does anyone know how I can preserve the aspect ratio of an image added using S:BitmapImage in flex 4. In flex 3 the mx:image had a maintainAspectRatio property - there does not seem to be an equivalent on the spark component.

       

      I am trying the all the BitmapImage to occupy 80% of the container dimensions but not to alter the aspect ratio.

       

      Anyone any ideas?....

       

      many thanks,

       

      Mark.

        • 1. Re: How to preserve aspect ration of image in s:BitmapImage?
          David_F57 Level 5

          Hi,

           

          With bitmap image you only have the fillmode option which is clip/repeat/scale

           

          clip maintains aspect ratio but doesn't resize, repeat tiles the image and scale fits the image to the bitmapimage size and you lose aspect ratio.

           

          Its easier to just use mx:image (as you can see its the default in the component panel), bitmapimage is a leaner component and is better for skins etc.

           

          If you want to use bitmapimage you get the aspect ratio of the loaded image then set the bitmapimage size to suit both the aspect ratio and your container limitations, then the scale fillmode would simply fill the bitmapimage area and aspect ratio would be correct. This is a lot of effort when you can simply set the maintainaspectratio with mx:image.

           

           

          David.

          • 2. Re: How to preserve aspect ration of image in s:BitmapImage?
            David_F57 Level 5

            Hi,

             

            With bitmap image you only have the fillmode option which is clip/repeat/scale

             

            clip maintains aspect ratio but doesn't resize, repeat tiles the image and scale fits the image to the bitmapimage size and you lose aspect ratio.

             

            Its easier to just use mx:image (as you can see its the default in the component panel), bitmapimage is a leaner component and is better for skins etc.

             

            If you want to use bitmapimage you get the aspect ratio of the loaded image then set the bitmapimage size to suit both the aspect ratio and your container limitations, then the scale fillmode would simply fill the bitmapimage area and aspect ratio would be correct. This is a lot of effort when you can simply set the maintainaspectratio with mx:image.

             

             

            David.

            • 3. Re: How to preserve aspect ration of image in s:BitmapImage?
              MarkTaylor46 Level 2

              Thanks, for the repy, I need to use the s:BitmapImage as the source i am providing is a bitmap generated at runtime (via binding) mx:image does not seem to accept a bitmap as a source whereas s:BitmapImage does. I have no objection to using the mx:image tag if that's easier but the source i can provide is a bitmap.... how can i use a bitmap as the source of an mx:image tag?

               

              Thanks,

               

              Mark.