<?xml version="1.0" encoding="utf-8"?>
<s:Application 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="onCreationComplete(event)"
viewSourceURL="http://zaalabs.com/demo/TestZaaIL/srcview/index.html">
<fx:Script>
<![CDATA[
import cmodule.zaail.CLibInit;
import com.zaalabs.zaail.ZaaILInterface;
import mx.controls.Alert;
import mx.events.FlexEvent;
protected var lib:Object;
protected var loader:CLibInit;
protected var ref:FileReference;
protected var bmd:BitmapData;
protected function onCreationComplete(event:FlexEvent):void
{
loader = new CLibInit();
lib = loader.init();
ref = new FileReference();
addListeners();
}
protected function addListeners():void
{
ref.addEventListener(Event.SELECT, onFileSelected);
ref.addEventListener(Event.COMPLETE, onFileLoaded);
}
protected function onLoadClick(event:MouseEvent):void
{
ref.browse([ZaaILInterface.FILE_FILTER]);
}
protected function onFileSelected(event:Event):void
{
ref.load();
}
protected function onFileLoaded(event:Event):void
{
var fileContents:ByteArray = ref.data;
var output:ByteArray = new ByteArray();
loader.supplyFile(ref.name, fileContents);
lib.ilInit();
lib.ilOriginFunc(ZaaILInterface.IL_ORIGIN_UPPER_LEFT);
lib.ilEnable(ZaaILInterface.IL_ORIGIN_SET);
if(lib.ilLoadImage(ref.name) != 1) {
Alert.show("Could not load the selected image", "Error Loading Image");
}
var width:int = lib.ilGetInteger(ZaaILInterface.IL_IMAGE_WIDTH);
var height:int = lib.ilGetInteger(ZaaILInterface.IL_IMAGE_HEIGHT);
var depth:int = lib.ilGetInteger(ZaaILInterface.IL_IMAGE_DEPTH);
lib.ilGetPixels(0, 0, 0, width, height, depth, output);
output.position = 0;
bmd = new BitmapData(width, height);
bmd.setPixels(new Rectangle(0, 0, width, height), output);
previewImage.source = bmd; }
]]>
</fx:Script>
<s:Panel title="Test ZaaIL" width="100%" height="100%">
<s:BitmapImage id="previewImage" />
<s:controlBarContent>
<s:Button label="Load" click="onLoadClick(event)" />
</s:controlBarContent>
</s:Panel>
</s:Application>