Avg. Rating 3.7

Problem

Smoothing is not enabled by default on Image controls. This greatly reduces the quality of scaled images.

Solution

Create a custom Image control that enables smoothing by default.

Detailed explanation

There are already a handful of cookbook entries on image smoothing, but they either rely on the internal namespace or are more complicated than the solution presented below.

Usage is identical to the standard Image control:
<controls:SmoothImage source="@Embed(source='assets/images/example.png')" />

The custom control overrides the updateDisplayList() method to enable smoothing:
package
{
import flash.display.Bitmap;
import mx.controls.Image;

public class SmoothImage extends Image
{
override protected function updateDisplayList (unscaledWidth : Number, unscaledHeight : Number) : void
{
super.updateDisplayList (unscaledWidth, unscaledHeight);

// checks if the image is a bitmap
if (content is Bitmap)
{
var bitmap : Bitmap = content as Bitmap;

if (bitmap != null && bitmap.smoothing == false)
{
bitmap.smoothing = true;
}
}
}

}
}
SmoothImage.as.zip
[SmoothImage control]
Report abuse

Related recipes