Created
January 6, 2010 08:36
-
-
Save alexkojin/270139 to your computer and use it in GitHub Desktop.
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"?> | |
<mx:Module xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo" creationComplete="init()" layout="vertical" width="100%" height="100%"> | |
<fx:Script> | |
<![CDATA[ | |
import flash.filters.ShaderFilter; | |
[Embed(source="assets/bicubicResampling.pbj", mimeType="application/octet-stream")] | |
private var ResampleFilter:Class; | |
private function init():void{ | |
var width:int = int(newWidth.text); | |
var height:int = int(newHeight.text); | |
var bitmapData:BitmapData = new BitmapData(img.width, img.height); | |
bitmapData.draw(img); | |
var shader:Shader = new Shader(new ResampleFilter()); | |
shader.data.src.input = bitmapData; | |
shader.data.scale.value = [img.width/width, img.height/height]; | |
var res:BitmapData = new BitmapData(width, height); | |
var job:ShaderJob = new ShaderJob(shader); | |
job.target = res; | |
job.addEventListener(ShaderEvent.COMPLETE, completeHandler); | |
job.start(true); | |
} | |
function completeHandler(event:ShaderEvent):void | |
{ | |
out.removeChildAt(1); | |
out.addChild(new Bitmap(event.bitmapData)); | |
} | |
]]> | |
</fx:Script> | |
<mx:HBox> | |
<mx:VBox> | |
<mx:Image id="img" source="@Embed('assets/nikki.jpg')" /> | |
<mx:Image id="out" /> | |
</mx:VBox> | |
<mx:Grid> | |
<mx:GridRow> | |
<mx:GridItem> | |
<mx:Label text="New width" /> | |
</mx:GridItem> | |
<mx:GridItem> | |
<mx:TextInput id="newWidth" text="75" /> | |
</mx:GridItem> | |
</mx:GridRow> | |
<mx:GridRow> | |
<mx:GridItem> | |
<mx:Label text="New height" /> | |
</mx:GridItem> | |
<mx:GridItem> | |
<mx:TextInput id="newHeight" text="75" /> | |
</mx:GridItem> | |
</mx:GridRow> | |
<mx:GridRow> | |
<mx:GridItem> | |
</mx:GridItem> | |
<mx:GridItem> | |
<mx:Button label="Resize" click="init()" /> | |
</mx:GridItem> | |
</mx:GridRow> | |
</mx:Grid> | |
</mx:HBox> | |
</mx:Module> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment