Exemple #1
0
        public byte[] ToByteArray()
        {
            var writer = new SwfWriter();

            bool compress = _allowCompression && _version >= MinVersionSupportedComression;

            //write header
            writer.Write(compress ? SigCWS : SigFWS);

            writer.WriteUInt8((byte)_version);     //file version

            //NOTE: Comment below is from SWF specification.
            //The FileLength field is the total length of the SWF file, including the header. If this is an
            //uncompressed SWF file (FWS signature), the FileLength field should exactly match the file
            //size. If this is a compressed SWF file (CWS signature), the FileLength field indicates the total
            //length of the file after decompression, and thus generally does not match the file size.

            var data = GetFileData();
            int len  = data.Length;

            if (compress)
            {
                data = Zip.Compress(data);
                //if (data.Length > len)
                //    len = data.Length;
            }

            writer.WriteUInt32((uint)(8 + len)); //file length
            writer.Write(data);

            data = writer.ToByteArray();
            return(data);
        }
Exemple #2
0
        public void Write(SwfWriter writer)
        {
            WriteFlags(writer, Flags);

            var eventWriter = new SwfWriter {
                FileVersion = writer.FileVersion
            };

            if ((Flags & SwfEventFlags.KeyPress) != 0)
            {
                eventWriter.WriteUInt8(KeyCode);
            }
            _actions.Write(eventWriter);

            var eventData = eventWriter.ToByteArray();

            writer.WriteUInt32((uint)eventData.Length);
            writer.Write(eventData);
        }
Exemple #3
0
        private byte[] GetFileData()
        {
            if (_autoFrameCount)
            {
                _frameCount = (ushort)_tags.Count(tag => tag.TagCode == SwfTagCode.ShowFrame);
            }

            var writer = new SwfWriter();

            int w = _frameSize.Width.ToTwips();
            int h = _frameSize.Height.ToTwips();

            writer.WriteRect(0, 0, w, h);     //frame size
            writer.WriteUFloat16(_frameRate); //frame rate
            writer.WriteUInt16(_frameCount);  //frame count

            //tags (content)
            _tags.Write(writer);

            return(writer.ToByteArray());
        }