- 本站大部分内容从网上收集,收集目的仅供研究、学习。涉及版权或不希望收录您的文章请您及时与我联系。
- 本站IM群,请自行选择。请各位朋友按照自己喜好加入。加入群后请及时发言,防止被清理。谢谢您的合作!!!
- QQ群:Y①WEB开发(ASP.NET)号码:7351660 QQ群:Y②WEB开发(ASP+.NET)号码:11864905
- QQ群:Y③WEB开发(DIV+CSS)号码:16610506 QQ群:Y④WEB开发(JS+AJAX)号码:16143998
- QQ群:Y⑤WEB开发(新手)号码:12777715 MSN群:yaosansi[at]126.com
原文:http://www.roading.net/blog/article.asp?id=43
swf文件在flash6以后多了压缩的选项,使用zlib压缩,有人写的zlib的链接库(http://zlibnetwrapper.sourceforge.net/),在他们的网页里面有详细的使用帮助.
下面是我写的解压缩,压缩和读取flash头文件信息的代码:
压缩:
1: openFileDialog1.Filter = "JPG Files|*.swf";
2: openFileDialog1.Title = "Select a Swf File";
3: if(openFileDialog1.ShowDialog() == DialogResult.OK)
4: { 5: string fileName = Path.GetFullPath(openFileDialog1.FileName);
6: FileStream fs1 = new FileStream(fileName, FileMode.Open, FileAccess.Read);
7: BinaryReader r = new BinaryReader(fs1);
8: byte[] writedata = r.ReadBytes((int)(fs1.Length - 1));
9: ManagedZLib.ManagedZLib.Initialize(); 10: string tempfile = "aaa.swf";
11: FileStream fs = new FileStream(tempfile, FileMode.OpenOrCreate);
12: byte[] writefiledata = new byte[8];
13: writefiledata[0] = Convert.ToByte('C');
14: for(int i=1;i<8;i++)
15: { 16: writefiledata[i] = writedata[i]; 17: } 18: fs.Write(writefiledata,0,8); 19: ManagedZLib.CompressionStream zlibStream = new ManagedZLib.CompressionStream(fs, ManagedZLib.CompressionOptions.CompressBest);
20: BinaryWriter zlibWriter = new BinaryWriter(zlibStream);
21: zlibWriter.Write(writedata,8,writedata.Length - 8); 22: zlibWriter.Close(); 23: zlibStream.Close(); 24: r.Close(); 25: fs1.Close(); 26: } 解压缩:
1: FileStream stream [color=#0000ff]= new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
2: BinaryReader reader = new BinaryReader(stream);
3: try
4: { 5: byte[] dataPart = new byte[stream.Length-8];
6: string mark = new string(reader.ReadChars(3));
7: if(mark == "FWS")
8: { 9: MessageBox.Show("已经是解压缩过的文件");
10: return;
11: } 12: int version = Convert.ToInt32(reader.ReadByte());
13: int fileLength = reader.ReadInt32();
14: reader.Read(dataPart, 0, dataPart.Length); 15: byte[] savedata = new byte[fileLength];
16: savedata[0] = Convert.ToByte('F');
17: savedata[1] = Convert.ToByte('W');
18: savedata[2] = Convert.ToByte('S');
19: savedata[3] = version; 20: savedata[4] = Convert.ToByte(fileLength%256); 21: savedata[5] = Convert.ToByte(fileLength/256%256); 22: savedata[6] = Convert.ToByte(fileLength/256/256%256); 23: savedata[7] = Convert.ToByte(fileLength/256/256/256%256); 24: MemoryStream dataStream = new MemoryStream(dataPart);
25: try
26: { 27: ManagedZLib.ManagedZLib.Initialize(); 28: ManagedZLib.CompressionStream zlibStream = new ManagedZLib.CompressionStream(dataStream, ManagedZLib.CompressionOptions.Decompress);
29: BinaryReader zlibReader = new BinaryReader(zlibStream);
30: try
31: { 32: byte[] decompressedPart = new byte[fileLength - 8];
33: zlibReader.Read(decompressedPart, 0, decompressedPart.Length); 34: for(int i=8;i<fileLength;i++)
35: { 36: savedata[i] = decompressedPart[i-8]; 37: } 38: string FILE_NAME = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,filename);
39: FileStream fss = new FileStream(FILE_NAME, FileMode.OpenOrCreate);
40: BinaryWriter ww = new BinaryWriter(fss);
41: ww.Write(savedata); 42: ww.Close(); 43: fss.Close(); 44: } 45: finally
46: { 47: zlibReader.Close(); 48: zlibStream.Close(); 49: ManagedZLib.ManagedZLib.Terminate(); 50: } 51: } 52: finally
53: { 54: dataStream.Close(); 55: } 56: } 57: finally
58: { 59: reader.Close(); 60: stream.Close(); 61: } 读取头文件信息:
flash的头文件信息在flash文件格式一文中有详细的讲解,每个字节所代表的意思都有.
第4个字节flash 的版本
第5-8个字节代表flash文件大小
然后是flash文件的舞台大小和帧速率,帧数
订阅本站,阅读更多文章