The Flex Image control doesn’t expose Bitmap smoothing by default but can easily be added in through subclassing the component. Smoothing is a nice feature for removing jaggies from images that have been scaled either up or down, and in practice hasn’t caused any noticable cpu hangups to do the post processing. I’m writing up a patch to submit to the Flex Open Source initiative, but in the meantime, heres a quick and dirty hack to enable it in the Flex 2 and Flex 3 SDK.
Create a new MXML component and name it SmoothImage.mxml, then add the following code.
<?xml version="1.0" encoding="utf-8"?> <mx:Image xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <![CDATA[ import flash.display.Bitmap; override protected function updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void{ super.updateDisplayList(unscaledWidth, unscaledHeight); if(content is Bitmap){ var bmp:Bitmap = Bitmap(content); if(bmp && bmp.smoothing == false){ bmp.smoothing = true; } } } ]]> </mx:Script> </mx:Image>
Now just use <local:SmoothImage source=”myimage.jpg”/> the same way you’d use a normal image component and you’re all set. This code will take care of smoothing both dynamically loaded images as well as embedded images in one simple script. It also handles broken images gracefully. Heres a quick sample showing the affects of scaling the Google logo with and without smoothing.
And the code used to create this…
<!-- Top Images --> <mx:Image source="{googlelogo}" width="60" height="25"/> <mx:Image source="{googlelogo}" width="200" height="90"/> <mx:Image source="{googlelogo}" width="400" height="180"/> <!-- Bottom Images --> <local:SmoothImage source="{googlelogo}" width="60" height="25"/> <local:SmoothImage source="{googlelogo}" width="200" height="90"/> <local:SmoothImage source="{googlelogo}" width="400" height="180"/>