Flex 加载tiff

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

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

  

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <mx:Application creationComplete="init()" xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
 3     <mx:Script>
 4         <![CDATA[
 5         
 6             import tiff.Tiff;
 7             //这是一个flex工程
 8             private var loader:URLLoader;
 9             private var tiff_img:Tiff;
10             private var currentPageCount:int;
11             [Bindable] private var bitmap:Bitmap;            
12             
13             private function init():void{
14                 
15                 loader=new URLLoader(new URLRequest("cenfax_1245134002_519_0.tiff"));//读取图片
16                 loader.dataFormat=URLLoaderDataFormat.BINARY;
17                 loader.addEventListener(Event.COMPLETE,onComplete);
18             
19             }
20             private function onComplete(e:Event):void{
21                 
22                 var img:ByteArray=loader.data;
23                 tiff_img=new Tiff;
24                 tiff_img.read(img);//将图片数据传入,进行解码
25                 showPage(0);//返回的是一个bitmapdata对象
26             
27             }
28             //当按pre按钮
29             private function preClick():void{
30                 
31                 showPage(currentPageCount-1);
32             
33             }
34             //当按next按钮
35             private function nextClick():void{
36                 
37                 showPage(currentPageCount+1);
38             
39             }
40             //显示分页图片
41             private function showPage(num:int):void{
42                 
43                 if(!(num>tiff_img.getPageCount()-1||num<0)){
44                     bitmap=new Bitmap(tiff_img.getImage(num));
45                     currentPageCount=num;
46                     labelPage.text=num+1+"/"+tiff_img.getPageCount();
47                 }
48             
49             }
50         ]]>
51     </mx:Script>
52     <mx:Label id="labelPage" text="/" height="20" bottom="17" horizontalCenter="5"/>
53     <mx:Panel id="panel" layout="absolute" left="0" right="0" top="0" bottom="45">
54         <mx:Image id="image" source="{bitmap}">
55         </mx:Image>
56     </mx:Panel>
57     <mx:Button id="preBtn" label="Pre" left="122" bottom="10" click="preClick()"/>
58     <mx:Button id="nextBtn" label="Next" right="107" bottom="10" click="nextClick()"/>
59 </mx:Application>

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

posted @ 2015-12-08 17:18  haibalai  阅读(432)  评论(0编辑  收藏  举报