Flex 加载tiff

gis系统常常要加载tiff,因为好多土地证书,各种文件都是扫描件,如果你是用as来写的前台,怎么加载呢,顺便说下用插件AlternaTIFF也是可以得不过浏览器加载这么多插件是不太好的。

首先TIFF格式不仅仅是一种格式,它有相当多的标准,我在github上找到的TestZaaIL是可以加载一部分tiff,但是我系统的就不行,我还跟作者聊过,他说最好的方法是用后台方式解析,c++之类写的库。我还去搞c++也醉了,但是我记得之前团队写过一个as3的tiff类库 测试代码如下

 <?xml version="1.0" encoding="utf-8"?>
<mx:Application creationComplete="init()" xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[ import tiff.Tiff;
//这是一个flex工程
private var loader:URLLoader;
private var tiff_img:Tiff;
private var currentPageCount:int;
[Bindable] private var bitmap:Bitmap; private function init():void{ loader=new URLLoader(new URLRequest("cenfax_1245134002_519_0.tiff"));//读取图片
loader.dataFormat=URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE,onComplete); }
private function onComplete(e:Event):void{ var img:ByteArray=loader.data;
tiff_img=new Tiff;
tiff_img.read(img);//将图片数据传入,进行解码
showPage(0);//返回的是一个bitmapdata对象 }
//当按pre按钮
private function preClick():void{ showPage(currentPageCount-1); }
//当按next按钮
private function nextClick():void{ showPage(currentPageCount+1); }
//显示分页图片
private function showPage(num:int):void{ if(!(num>tiff_img.getPageCount()-1||num<0)){
bitmap=new Bitmap(tiff_img.getImage(num));
currentPageCount=num;
labelPage.text=num+1+"/"+tiff_img.getPageCount();
} }
]]>
</mx:Script>
<mx:Label id="labelPage" text="/" height="20" bottom="17" horizontalCenter="5"/>
<mx:Panel id="panel" layout="absolute" left="0" right="0" top="0" bottom="45">
<mx:Image id="image" source="{bitmap}">
</mx:Image>
</mx:Panel>
<mx:Button id="preBtn" label="Pre" left="122" bottom="10" click="preClick()"/>
<mx:Button id="nextBtn" label="Next" right="107" bottom="10" click="nextClick()"/>
</mx:Application>

具体源码下载http://files.cnblogs.com/files/haibalai/tifflib.rar 但是还是解决不了问题,tiff格式太广泛了,as想要还原所有解码还是麻烦,AlternaTIFF是一种不错解决方案了。

上一篇:SQL查询几种的区别。


下一篇:Tiff – 值得你体验一下的可视化的字体对比工具