Setting the corner radius on a Spark BitmapImage control in Flex 4

The following example shows how you can set the corner radius on a Spark BitmapImage control in Flex 4 by creating a mask with a corner radius (in this case a Spark BorderContainer container with the cornerRadius style set).

The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, see To download the latest nightly build of the Flex 4 SDK, see

For more information on getting started with Flex 4 and Flash Builder 4, see the official Adobe Flex Team blog.

<?xml version="1.0" encoding="utf-8"?>
<!-- -->
<s:Application name="Spark_BitmapImage_cornerRadius_test"
            <mx:FormItem label="cornerRadius:">
                <s:HSlider id="sl"
                        maximum="{bmpImg.height/2}" />
    <s:BitmapImage id="bmpImg"
            horizontalCenter="0" verticalCenter="0">
            <s:BorderContainer id="bmpMask"
                    width="{bmpImg.width}" height="{bmpImg.height}" />


View source is enabled in the following example.

Due to popular demand, here is the “same” example in a more ActionScript friendly format:

<?xml version="1.0" encoding="utf-8"?>
<!-- -->
<s:Application name="Spark_BitmapImage_cornerRadius_test"
            import mx.containers.Form;
            import mx.containers.FormItem;
            import mx.core.FlexGlobals;
            import spark.components.BorderContainer;
            import spark.components.HSlider;
            import spark.primitives.BitmapImage;
            protected const IMG:Class;
            protected var sl:HSlider;
            protected var bmpImg:BitmapImage;
            protected var bmpMask:BorderContainer;
            protected function init():void {
                var image:Object = new IMG();
                sl = new HSlider();
                sl.maximum = image.height / 2;
                sl.addEventListener(Event.CHANGE, sl_changeHandler);
                var frmItm:FormItem = new FormItem();
                frmItm.label = "cornerRadius:";
                var frm:Form = new Form();
                Application(FlexGlobals.topLevelApplication).controlBarContent = [frm];
                bmpMask = new BorderContainer();
                bmpMask.setStyle("cornerRadius", sl.value);
                bmpMask.width = image.width;
                bmpMask.height = image.height;
                bmpImg = new BitmapImage();
                bmpImg.source = image;
                bmpImg.mask = bmpMask;
                bmpImg.horizontalCenter = 0;
                bmpImg.verticalCenter = 0;
            protected function sl_changeHandler(evt:Event):void {
                bmpMask.setStyle("cornerRadius", sl.value);

This entry is based on a beta version of the Flex 4 SDK and therefore is very likely to change as development of the Flex SDK continues. The API can (and will) change causing examples to possibly not compile in newer versions of the Flex 4 SDK.

4 thoughts on “Setting the corner radius on a Spark BitmapImage control in Flex 4

  1. Hi
    How can i add an image to the Embed tag whose url i create dynamically to the bitmap source?
    I create it in the following way “”+id+”/45.jpg”

    Thanks in advance

Comments are closed.