1 person found this helpful
If you want to fill the 'screen' but maintain aspect ratio you need to either over size the image and center it or adjust the height by the aspect ratio to match the width of the screen. The following will just place the image in the top left hand corner stretch it to the width of the screen then adjust the height. The math can get a little more complex if you want to ensure that the height is completely covered. For example test the screen aspect ratio against the image aspect ratio to determine whether you are going to clip the bottom or clip the right hand side.
You can experiment with maintainAspectRatio and scaleContent being true or false, but in the end you will need to do some programmatic resizing of the image container.
<mx:Image id="bg" maintainAspectRatio="true" scaleContent="true" top="0" left="0" right="0" creationComplete="image1_creationCompleteHandler(event)"/>
protected function image1_creationCompleteHandler(event:FlexEvent):void
ar = bg.contentWidth/bg.contentHeight;
bg.height = width/ar;
I did find a solution similar to yours that works. However, I think this should be covered by some native FB functionality.
autoBestFit... In a perfect world that would be nice, unfortunately ...................
the spark image component has a mode property that is more inline with your standard image sizing it has clip/scale/tile, but it lacks some of the nicities of mx image (spark bitmapimage is a light weight component). I suppose in combination of minwidth/minheight you could get semi best fit. If you are feeling couragous you could extend the image component with a bestfit algorithm .
I suppose in combination of minwidth/minheight you could get semi best fit. If you are feeling couragous you could extend the image component with a bestfit algorithm .
Thanks again for the input David.
Yes there seem to be room for an extended and improved image class here.
I`ll put it on my todo list !