ORM映射框架总结--Flash 处理

简介: 代码   1 /**  2  *   3  * 2009-4-17  4  *   5  *   6  * 根据flash读取其宽度和高度  7  * */  8 using System;  9 using System.
img_405b18b4b6584ae338e0f6ecaf736533.gif 代码
  1  /* *
  2   * 
  3   * 2009-4-17
  4   * 
  5   * 
  6   * 根据flash读取其宽度和高度
  7   *  */
  8  using  System;
  9  using  System.Collections.Generic;
 10  using  System.Linq;
 11  using  System.Text;
 12  using  System.IO;
 13  using  System.Collections;
 14 
 15  namespace  CommonData.Flash
 16  {
 17      [Serializable]
 18       public   partial   class  FlashInfo
 19      {
 20           private   int  width, height, version, frameCount, fileLength;
 21           private   float  frameRate;
 22           private   bool  isCompressed;
 23 
 24           public  FlashInfo( string  filename)
 25          {
 26               if  ( ! File.Exists(filename))
 27              {
 28                   throw   new  FileNotFoundException(filename);
 29              }
 30              FileStream stream  =   new  FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
 31              BinaryReader reader  =   new  BinaryReader(stream);
 32               try
 33              {
 34                   if  (stream.Length  <   8 )
 35                  {
 36                       throw   new  InvalidDataException( " 文件不是 Flash 文件格式 " );
 37                  }
 38                   string  flashMark  =   new   string (reader.ReadChars( 3 ));
 39                   if  (flashMark  !=   " FWS "   &&  flashMark  !=   " CWS " )
 40                  {
 41                       throw   new  InvalidDataException( " 文件不是 Flash 文件格式 " );
 42                  }
 43                  isCompressed  =  flashMark  ==   " CWS " ;
 44                  version  =  Convert.ToInt32(reader.ReadByte());
 45                  fileLength  =  reader.ReadInt32();
 46                   byte [] dataPart  =   new   byte [stream.Length  -   8 ];
 47                  reader.Read(dataPart,  0 , dataPart.Length);
 48                  MemoryStream dataStream  =   new  MemoryStream(dataPart);
 49                   try
 50                  {
 51                       if  (isCompressed)
 52                      {
 53                          MemoryStream outStream  =   new  MemoryStream();
 54                          zlib.ZOutputStream outZStream  =   new  zlib.ZOutputStream(outStream);
 55                          CopyStream(dataStream, outZStream);
 56                          outStream.Position  =   0 ;
 57                          ProcessCompressedPart(outStream);
 58                          outZStream.Close();
 59                          outStream.Close();
 60                      }
 61                       else
 62                          ProcessCompressedPart(dataStream);
 63                  }
 64                   finally
 65                  {
 66                      dataStream.Close();
 67                  }
 68              }
 69               finally
 70              {
 71                  reader.Close();
 72                  stream.Close();
 73              }
 74          }
 75 
 76           private   void  ProcessCompressedPart(MemoryStream stream)
 77          {
 78              BinaryReader reader  =   new  BinaryReader(stream);
 79               try
 80              {
 81                   byte [] rect;
 82                   int  nbits, totalBits, totalBytes;
 83                  nbits  =  reader.ReadByte()  >>   3 ;
 84                  totalBits  =  nbits  *   4   +   5 ;
 85                  totalBytes  =  totalBits  /   8 ;
 86                   if  (totalBits  %   8   !=   0 )
 87                  {
 88                      totalBytes ++ ;
 89                  }
 90                  reader.BaseStream.Seek( - 1 , SeekOrigin.Current);
 91                  rect  =  reader.ReadBytes(totalBytes);
 92                  frameRate  =   float .Parse( string .Format( " {1}.{0} " , reader.ReadByte(), reader.ReadByte()));
 93                  frameCount  =  Convert.ToInt32(reader.ReadInt16());
 94                  BitArray bits  =   new  BitArray(rect);
 95                   bool [] reversedBits  =   new   bool [bits.Length];
 96                   for  ( int  i  =   0 ; i  <  totalBytes; i ++ )
 97                  {
 98                       int  count  =   7 ;
 99                       for  ( int  j  =   8   *  i; j  <   8   *  (i  +   1 ); j ++ )
100                      {
101                          reversedBits[j  +  count]  =  bits[j];
102                          count  -=   2 ;
103                      }
104                  }
105                  bits  =   new  BitArray(reversedBits);
106                  StringBuilder sbField  =   new  StringBuilder(bits.Length);
107                   for  ( int  i  =   0 ; i  <  bits.Length; i ++ )
108                      sbField.Append(bits[i]  ?   " 1 "  :  " 0 " );
109                   string  result  =  sbField.ToString();
110                   string  widthBinary  =  result.Substring(nbits  +   5 , nbits);
111                   string  heightBinary  =  result.Substring( 3   *  nbits  +   5 , nbits);
112                  width  =  Convert.ToInt32(FlashInfo.BinaryToInt64(widthBinary)  /   20 );
113                  height  =  Convert.ToInt32(FlashInfo.BinaryToInt64(heightBinary)  /   20 );
114              }
115               finally
116              {
117                  reader.Close();
118              }
119          }
120 
121           private   static   long  BinaryToInt64( string  binaryString)
122          {
123               if  ( string .IsNullOrEmpty(binaryString))
124                   throw   new  ArgumentNullException();
125               long  result  =   0 ;
126               for  ( int  i  =   0 ; i  <  binaryString.Length; i ++ )
127              {
128                  result  =  result  *   2 ;
129                   if  (binaryString[i]  ==   ' 1 ' )
130                      result ++ ;
131              }
132               return  result;
133          }
134 
135           public   int  Width
136          {
137               get
138              {
139                   return   this .width;
140              }
141          }
142 
143           public   int  Height
144          {
145               get
146              {
147                   return   this .height;
148              }
149          }
150 
151           public   int  FileLength
152          {
153               get
154              {
155                   return   this .fileLength;
156              }
157          }
158 
159           public   int  Version
160          {
161               get
162              {
163                   return   this .version;
164              }
165          }
166 
167           public   float  FrameRate
168          {
169               get
170              {
171                   return   this .frameRate;
172              }
173          }
174 
175           public   int  FrameCount
176          {
177               get
178              {
179                   return   this .frameCount;
180              }
181          }
182 
183           public   bool  IsCompressed
184          {
185               get
186              {
187                   return   this .isCompressed;
188              }
189          }
190 
191           public   static   void  CopyStream(System.IO.Stream input, System.IO.Stream output)
192          {
193               byte [] buffer  =   new   byte [ 2000 ];
194               int  len;
195               while  ((len  =  input.Read(buffer,  0 2000 ))  >   0 )
196              {
197                  output.Write(buffer,  0 , len);
198              }
199              output.Flush();
200          }
201      }
202  }
203 

 

  这个类用于处理Flash文件的,可以获得falsh 的一些相关信息。这里需要一个插件的处理 zlib.net.dll。 可以到网上去下载

  

相关文章
|
Web App开发
ORM映射框架总结--文件下载
本段代码提供了asp.net 中的各种文件下载方式。   代码   1 /**  2  * 日期:2009-3-13  3  * 作者:  4  * 功能:下载文件  5  * */  6   7 using System;  8 using System.
598 0
|
Web App开发
ORM映射框架总结--Excel 操作
  在很多时候,我们需要将查询的数据做成报表统计,然后生成Excel文档格式的。再此提供了将DataTable 数据导出excel 的方法   代码   1 /**  2  *   3  * 2009-5-2  4  *   5  *   6  * 将DataTable导出为excel文件  7  * */  8 using System;  9 using System.
879 0
|
算法 数据安全/隐私保护
ORM映射框架总结--加密处理
1.MD5 加密处理 代码  1 /** 2  * 日期:2009-3-15 3  * 作者: 4  * 功能:MD5加密及验证 5  * */ 6 using System; 7 using System.
806 0
|
SQL 安全 数据库
ORM映射框架总结--代码生成器
年前发布了一些文章,是关于.NET数据操作(点击查看)的。刚开始学习编程的时候,总感觉Java中的Hibernate 功能好强大,现在也不可否认它的确强大,特别是它在数据关系处理上,却是那样的让人称叹。
1233 0
|
存储 SQL 数据库
ORM映射框架总结--数据操作(七)
2. 数据库操作实现类 SqlHelper 代码 /** *  * 2009-4-22 *  *  * 数据库操作的公共类 * */using System;using System.Collections.
672 0
|
SQL
ORM映射框架总结--数据操作(四)
1.BaseEntityHelper 解析实体类特性 代码   1 /**  2  *   3  * 2009-4-17  4  *   5  *   6  * 字段的特性  7  * */  8 using System;  9 using System.
725 0
|
数据库连接 数据库
ORM映射框架总结--数据操作(五)
1.数据库加载驱动和操作接口 IDbProvider 代码  1 /** 2  *  3  * 2009-4-22 4  *  5  *  6  * 数据库操作加载驱动接口,  7  * 提供了数据库操作的各种命令  8  * */ 9 using System;10 using System.
772 0
|
SQL 存储 数据库
ORM映射框架总结--数据操作(六)
1. 数据库操作接口 IDbHelper 代码 /** *  * 2009-4-22 *  *  * 提供各种数据库操作方法以及实体类操作方法 * */using System;using System.
632 0
|
SQL 存储 .NET
ORM映射框架总结--数据库操作库(精修版)
1.       ORM数据库操作原理 前面已经介绍过了个人ORM映射框架中的三个核心库: 实体—数据库 映射特性关系: http://www.cnblogs.com/qingyuan/archive/2010/04/02/1702998.
1364 0
|
数据库
ORM映射框架总结--映射桥梁
1.       感言 写博客之前先自我吹嘘一下,给这些文章来些自我介绍。 半年前自己借用了5个多月的业务时间写了一个个人ORM映射框架。在之前的博 客中也有过写过该框架的相关介绍。半年前的那个ORM只不过是自己想象的关系映射的一个雏形,那一段曾经让自己骄傲过得代码的确存在着太多的问题,但是我始终没有放弃过对它的修改。
811 0