Created
December 10, 2011 17:44
-
-
Save thanksmister/1455731 to your computer and use it in GitHub Desktop.
Flex Spark Image component with skin to make rounded corners and border.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<!-- | |
Michael Ritchie | |
[email protected] | |
Copyright 2011 ThanksMister LLC | |
Dec 10, 2011 | |
--> | |
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" | |
xmlns:s="library://ns.adobe.com/flex/spark" | |
xmlns:mx="library://ns.adobe.com/flex/mx" | |
creationComplete="windowedapplication1_creationCompleteHandler(event)"> | |
<fx:Style> | |
@namespace s "library://ns.adobe.com/flex/spark"; | |
@namespace mx "library://ns.adobe.com/flex/mx"; | |
s|Image { | |
cornerRadius:10; | |
} | |
</fx:Style> | |
<fx:Script> | |
<![CDATA[ | |
import mx.events.FlexEvent; | |
protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void | |
{ | |
loadFile(); | |
} | |
protected function loadFile():void | |
{ | |
var loader:Loader = new Loader(); | |
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onFileLoaded); | |
var urlRequest:URLRequest = new URLRequest("image.png"); | |
loader.load(urlRequest); | |
} | |
protected function onFileLoaded(e:Event):void | |
{ | |
var bmp:Bitmap = e.target.content as Bitmap; | |
var bitmapData:BitmapData = scaleImage(bmp.bitmapData, 100, 100); | |
var scaledBitmap:Bitmap = new Bitmap(bitmapData); | |
roundedImage.source = scaledBitmap; | |
} | |
protected function scaleImage(bitmapData:BitmapData, width:Number, height:Number):BitmapData | |
{ | |
// Calculate the scaled size. | |
var scale:Number; | |
var scaledWidth:Number; | |
var scaledHeight:Number; | |
scale = Math.min(width/(bitmapData.width as Number), height/(bitmapData.height as Number)) | |
scaledHeight = Math.round(bitmapData.height * scale); | |
scaledWidth = Math.round(bitmapData.width * scale); | |
var scalingMatrix:Matrix = new Matrix(); | |
scalingMatrix.scale(scale, scale); | |
// Scale the image. | |
var scaledImage:BitmapData = new BitmapData(scaledWidth, scaledHeight, true, 0x00000000); | |
scaledImage.draw(bitmapData, scalingMatrix, null, null, null, true); | |
bitmapData.dispose(); | |
return scaledImage; | |
} | |
]]> | |
</fx:Script> | |
<s:Group height="100" width="100%"> | |
<s:Image id="roundedImage" skinClass="ImageButtonSkin" horizontalCenter="0" verticalCenter="0"/> | |
</s:Group> | |
</s:WindowedApplication> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment