示例#1
0
        public void Write(SwfWriter writer)
        {
            writer.WriteUIntEncoded((uint)_method.Index);
            writer.WriteUIntEncoded((uint)MaxStackDepth);
            writer.WriteUIntEncoded((uint)LocalCount);
            writer.WriteUIntEncoded((uint)MinScopeDepth);
            writer.WriteUIntEncoded((uint)MaxScopeDepth);

            if (_il != null)
            {
                using (var codeWriter = new SwfWriter())
                {
                    codeWriter.ABC = writer.ABC;
                    _il.Write(codeWriter);
                    var code = codeWriter.ToByteArray();
                    writer.WriteUIntEncoded((uint)code.Length);
                    writer.Write(code);
                }
            }
            else
            {
                writer.WriteUInt8(0);
            }

            _exceptions.Write(writer);
            _traits.Write(writer);
        }
示例#2
0
 protected override void WriteBody(SwfWriter writer)
 {
     if (Body != null)
     {
         writer.Write(Body);
     }
 }
示例#3
0
 public override void WriteTagData(SwfWriter writer)
 {
     if (Data != null)
     {
         writer.Write(Data);
     }
 }
        public void WriteSwf(string fileName)
        {
            Stream    stream = new FileStream(fileName, FileMode.Create);
            SwfWriter writer = new SwfWriter(stream);

            writer.Write(swf);
            stream.Close();
        }
示例#5
0
 protected override void WriteData(SwfWriter writer)
 {
     Debug.Assert(SampleSize == 8 || SampleSize == 16);
     writer.WriteUB((uint)Format, 4);
     writer.WriteUB((uint)Rate, 2);
     writer.WriteBit(SampleSize == 16);
     writer.WriteBit(SoundType == FlvSoundType.Stereo);
     writer.Write(SoundData);
 }
示例#6
0
        private static void WriteIndexed(SwfWriter writer, Bitmap bmp, bool alpha)
        {
            int w = bmp.Width;
            int h = bmp.Height;

            writer.WriteUInt8((byte)SwfBitmapFormat.Indexed);
            writer.WriteUInt16((ushort)w);
            writer.WriteUInt16((ushort)h);

            var pal     = bmp.Palette.Entries;
            int palSize = pal.Length;

            writer.WriteUInt8((byte)(palSize - 1));

            var bmpWriter = new SwfWriter();

            for (int i = 0; i < palSize; ++i)
            {
                bmpWriter.WriteColor(pal[i], alpha);
            }

            //NOTE: Row widths in the pixel data fields of these structures must be rounded up to the next
            //32-bit word boundary. For example, an 8-bit image that is 253 pixels wide must be
            //padded out to 256 bytes per line. To determine the appropriate padding, make sure to
            //take into account the actual size of the individual pixel structures; 15-bit pixels occupy 2
            //bytes and 24-bit pixels occupy 4 bytes (see PIX15 and PIX24).

            int pad = w % 4;

            if (pad != 0)
            {
                pad = 4 - pad;
            }

            using (var fbmp = new FastBitmap(bmp))
            {
                for (int y = 0; y < h; ++y)
                {
                    for (int x = 0; x < w; ++x)
                    {
                        int index = fbmp.GetIndex(x, y);
                        Debug.Assert(index >= 0 && index < palSize);
                        bmpWriter.WriteUInt8((byte)index);
                    }
                    if (pad > 0)
                    {
                        bmpWriter.Pad(pad);
                    }
                }
            }

            var data = bmpWriter.ToByteArray();

            data = Zip.Compress(data);
            writer.Write(data);
        }
示例#7
0
        public static void ConvertBmpToSwf(Bitmap bmp, string outputSwfFileName)
        {
            int   posX   = 0; //Posx
            int   posY   = 0; //Posy
            Image image  = bmp;
            int   width  = image.Width;
            int   height = image.Height;

            //自动缩小大图片
            if (width > 610)
            {
                double rw        = width;
                double rh        = height;
                double newheight = rh * 610 / rw;
                width  = 610;
                height = Convert.ToInt32(newheight);
                image  = image.GetThumbnailImage(width, height, null, IntPtr.Zero);
            }
            Swf swf = new Swf();

            swf.Size             = new Rect(0, 0, (posX + width) * 20, (posY + height) * 20);
            swf.Version          = 7;
            swf.Header.Signature = "CWS";
            swf.Tags.Add(new SetBackgroundColorTag(255, 255, 255));
            ushort newDefineId = swf.GetNewDefineId();

            swf.Tags.Add(DefineBitsJpeg2Tag.FromImage(newDefineId, image));
            DefineShapeTag tag = new DefineShapeTag();

            tag.CharacterId = swf.GetNewDefineId();
            tag.Rect        = new Rect((posX * 20) - 1, (posY * 20) - 1, ((posX + width) * 20) - 1, ((posY + height) * 20) - 1);
            FillStyleCollection fillStyleArray = new FillStyleCollection();

            fillStyleArray.Add(new BitmapFill(FillStyleType.ClippedBitmapFill, 0xffff, new Matrix(0, 0, 20.0, 20.0)));
            fillStyleArray.Add(new BitmapFill(FillStyleType.ClippedBitmapFill, newDefineId, new Matrix((posX * 20) - 1, (posY * 20) - 1, (20.0 * width) / ((double)image.Width), (20.0 * height) / ((double)image.Height))));
            LineStyleCollection   lineStyleArray = new LineStyleCollection();
            ShapeRecordCollection shapes         = new ShapeRecordCollection();

            shapes.Add(new StyleChangeRecord((posX * 20) - 1, (posY * 20) - 1, 2));
            shapes.Add(new StraightEdgeRecord(width * 20, 0));
            shapes.Add(new StraightEdgeRecord(0, height * 20));
            shapes.Add(new StraightEdgeRecord(-width * 20, 0));
            shapes.Add(new StraightEdgeRecord(0, -height * 20));
            shapes.Add(new EndShapeRecord());
            tag.ShapeWithStyle = new ShapeWithStyle(fillStyleArray, lineStyleArray, shapes);
            swf.Tags.Add(tag);
            swf.Tags.Add(new PlaceObject2Tag(tag.CharacterId, 1, 0, 0));
            swf.Tags.Add(new ShowFrameTag());
            swf.Tags.Add(new EndTag());
            SwfWriter writer = new SwfWriter(outputSwfFileName);

            writer.Write(swf);
            writer.Close();
            image.Dispose();
        }
示例#8
0
        private static void WriteRGB24(SwfWriter writer, Bitmap bmp, bool alpha)
        {
            writer.WriteUInt8((byte)SwfBitmapFormat.RGB24);
            writer.WriteUInt16((ushort)bmp.Width);
            writer.WriteUInt16((ushort)bmp.Height);

            var data = GetRGB24(bmp, alpha);

            data = Zip.Compress(data);
            writer.Write(data);
        }
示例#9
0
        protected override void WriteBody(SwfWriter writer)
        {
            var ms = new MemoryStream();

            Image.Save(ms, ImageFormat.Jpeg);
            ms.Flush();
            ms.Close();
            var data = ms.ToArray();

            writer.Write(data);
        }
示例#10
0
        public void Write(SwfWriter writer)
        {
            writer.WriteUInt8((byte)Type);
            var data = GetData();

            writer.WriteUInt24BE((uint)data.Length);
            writer.WriteUInt24BE((uint)TimeStamp);
            writer.WriteUInt8((byte)TimeStampExtended);
            writer.WriteUInt24BE((uint)StreamId);
            writer.Write(data);
        }
示例#11
0
        static void Main(string[] args)
        {
            Swf swf = new Swf();

            swf.Version = 5;
            swf.Tags.Add(new SetBackgroundColorTag(new RGB(0, 0, 255)));
            swf.Tags.Add(new ShowFrameTag());
            swf.Tags.Add(new EndTag());

            SwfWriter writer = new SwfWriter(path);

            writer.Write(swf);
            writer.Close();
        }
示例#12
0
        protected override void WriteBody(SwfWriter writer)
        {
            var ms = new MemoryStream();

            Image.Save(ms, ImageFormat.Jpeg);
            ms.Flush();
            ms.Close();
            var jpeg = ms.ToArray();

            writer.WriteUInt32((uint)jpeg.Length);
            writer.Write(jpeg);

            //TODO: write alpha
        }
示例#13
0
        public void Write(SwfWriter writer)
        {
            int n = Count;

            for (int i = 0; i < n; ++i)
            {
                var tag       = this[i];
                var tagWriter = new SwfWriter {
                    FileVersion = writer.FileVersion
                };
                tag.Write(tagWriter);
                var tagData = tagWriter.ToByteArray();
                writer.WriteUInt32BE((uint)tagData.Length);
                writer.Write(tagData);
            }
        }
示例#14
0
 public void Write(SwfWriter writer)
 {
     foreach (var action in this)
     {
         byte code = (byte)action.ActionCode;
         writer.WriteUInt8(code);
         if (code >= ActionsWithData)
         {
             var data = action.GetData();
             writer.WriteUInt16((ushort)data.Length);
             writer.Write(data);
         }
     }
     if (Count <= 0 || this[Count - 1].ActionCode != SwfActionCode.End)
     {
         writer.WriteUInt8(0);
     }
 }
示例#15
0
        public static void WriteAbcConst <T>(this SwfWriter writer, T value)
        {
            var typeCode = Type.GetTypeCode(typeof(T));

            switch (typeCode)
            {
            case TypeCode.Int32:
                writer.WriteIntEncoded((int)(object)value);
                break;

            case TypeCode.UInt32:
                writer.WriteUIntEncoded((uint)(object)value);
                break;

            case TypeCode.Double:
                writer.WriteDouble((double)(object)value);
                break;

            case TypeCode.String:
            {
                var s = value as string;
                if (string.IsNullOrEmpty(s))
                {
                    writer.WriteUIntEncoded(0);
                }
                else
                {
                    var data = Encoding.UTF8.GetBytes(s);
                    writer.WriteUIntEncoded((uint)data.Length);
                    writer.Write(data);
                }
            }
            break;

            default:
                throw new NotImplementedException();
            }
        }
示例#16
0
 public override void WriteTagData(SwfWriter writer)
 {
     writer.Write(Data);
 }
示例#17
0
 protected override void WriteBody(SwfWriter writer)
 {
     writer.WriteUInt32(0); //reserved
     writer.Write(Data);
 }
示例#18
0
        /// <summary>
        /// 生成flash
        /// </summary>
        /// <param name="imgFilePaths"></param>
        /// <param name="saveSwfFilePath"></param>
        /// <returns></returns>
        public static bool CreateSwf(List <string> imgFilePaths, string saveSwfFilePath)
        {
            try {
                Swf swf = new Swf();
                foreach (var item in imgFilePaths)
                {
                    if (!new FileInfo(item).Exists)
                    {
                        continue;
                    }
                    Image img = Image.FromFile(item);
                    img = img.GetThumbnailImage(img.Width / 2, img.Height / 2, null, IntPtr.Zero);
                    int posX      = 0;
                    int posY      = 0;
                    int imgWidth  = img.Width;
                    int imgHeight = img.Height;
                    //Create a new Swf instance
                    //Set size in inch unit (1 pixel = 20 inches)
                    swf.Size             = new Rect(0, 0, (posX + imgWidth) * 20, (posY + imgHeight) * 20);
                    swf.Version          = 7;     //Version 7 (for compression, must be > 5)
                    swf.Header.Signature = "CWS"; //Set the signature to compress the swf
                    //Set the background color tag as white
                    swf.Tags.Add(new SetBackgroundColorTag(255, 255, 255));
                    //Set the jpeg tag
                    ushort jpegId = swf.GetNewDefineId();
                    //Load the jped directly from an image
                    //In fact, this line will load the jpeg data in the file as
                    //a library element only (not to display the jpeg)
                    swf.Tags.Add(DefineBitsJpeg2Tag.FromImage(jpegId, img));
                    //Now we will define the picture's shape tag
                    //to define all the transformations on the picture
                    //(as rotation, color effects, etc..)
                    DefineShapeTag shapeTag = new DefineShapeTag();
                    shapeTag.CharacterId = swf.GetNewDefineId();
                    shapeTag.Rect        = new Rect(posX * 20 - 1, posY * 20 - 1,
                                                    (posX + imgWidth) * 20 - 1, (posY + imgHeight) * 20 - 1);
                    FillStyleCollection fillStyles = new FillStyleCollection();
                    fillStyles.Add(new BitmapFill(FillStyleType.ClippedBitmapFill,
                                                  ushort.MaxValue, new Matrix(0, 0, 20, 20)));
                    fillStyles.Add(new BitmapFill(FillStyleType.ClippedBitmapFill,
                                                  jpegId, new Matrix(posX * 20 - 1, posY * 20 - 1,
                                                                     (20.0 * imgWidth) / img.Width,
                                                                     (20.0 * imgHeight) / img.Height)));
                    LineStyleCollection   lineStyles = new LineStyleCollection();
                    ShapeRecordCollection shapes     = new ShapeRecordCollection();
                    shapes.Add(new StyleChangeRecord(posX * 20 - 1, posY * 20 - 1, 2));
                    shapes.Add(new StraightEdgeRecord(imgWidth * 20, 0));
                    shapes.Add(new StraightEdgeRecord(0, imgHeight * 20));
                    shapes.Add(new StraightEdgeRecord(-imgWidth * 20, 0));
                    shapes.Add(new StraightEdgeRecord(0, -imgHeight * 20));
                    shapes.Add(new EndShapeRecord());
                    shapeTag.ShapeWithStyle =
                        new ShapeWithStyle(fillStyles, lineStyles, shapes);
                    swf.Tags.Add(shapeTag);

                    //Place the picture to the screen with depth=1
                    swf.Tags.Add(new PlaceObject2Tag(shapeTag.CharacterId, 1, 0, 0));
                    swf.Tags.Add(new ShowFrameTag());
                    swf.Tags.Add(new RemoveObject2Tag(1)); //THE ADDED LINE!!//
                    img.Dispose();
                }
                //Write the swf to a file
                SwfWriter writer = new SwfWriter(saveSwfFilePath);
                writer.Write(swf);
                writer.Close();
                return(true);
            } catch {
                return(false);
            }
        }
示例#19
0
        static void Main(string[] args)
        {
            //Picture to transform
            string imgPath = "img.jpg";
            string path    = "test_alpha.swf";
            //Alpha translation informations
            int alphaFrameNum = 35;  //frame duration
            int alphaStart    = 10;  //alpha percent start
            int alphaEnd      = 100; //alpha percent end

            //Load the picture to a GDI image
            Image img       = Image.FromFile(imgPath);
            int   posX      = 0;
            int   posY      = 0;
            int   imgWidth  = img.Width / 2;
            int   imgHeight = img.Height / 2;

            //Create a new Swf instance
            Swf swf = new Swf();

            swf.Size    = new Rect(0, 0, (posX + imgWidth) * 20, (posY + imgHeight) * 20);
            swf.Version = 5;

            //Set the background color tag
            swf.Tags.Add(new SetBackgroundColorTag(255, 255, 255));

            //Set the jpeg tag
            ushort jpegId = swf.GetNewDefineId();

            //Load the jped from an image
            swf.Tags.Add(DefineBitsJpeg2Tag.FromImage(jpegId, img));

            //Define the picture's shape tag
            DefineShapeTag shapeTag = new DefineShapeTag();

            shapeTag.CharacterId = swf.GetNewDefineId();
            shapeTag.Rect        = new Rect(posX * 20 - 1, posY * 20 - 1, (posX + imgWidth) * 20 - 1, (posY + imgHeight) * 20 - 1);
            FillStyleCollection fillStyles = new FillStyleCollection();

            fillStyles.Add(new BitmapFill(FillStyleType.ClippedBitmapFill, ushort.MaxValue, new Matrix(0, 0, 20, 20)));
            fillStyles.Add(new BitmapFill(FillStyleType.ClippedBitmapFill, jpegId, new Matrix(posX * 20 - 1, posY * 20 - 1, (20.0 * imgWidth) / img.Width, (20.0 * imgHeight) / img.Height)));
            LineStyleCollection   lineStyles = new LineStyleCollection();
            ShapeRecordCollection shapes     = new ShapeRecordCollection();

            shapes.Add(new StyleChangeRecord(posX * 20 - 1, posY * 20 - 1, 2));
            shapes.Add(new StraightEdgeRecord(imgWidth * 20, 0));
            shapes.Add(new StraightEdgeRecord(0, imgHeight * 20));
            shapes.Add(new StraightEdgeRecord(-imgWidth * 20, 0));
            shapes.Add(new StraightEdgeRecord(0, -imgHeight * 20));
            shapes.Add(new EndShapeRecord());
            shapeTag.ShapeWithStyle = new ShapeWithStyle(fillStyles, lineStyles, shapes);
            swf.Tags.Add(shapeTag);

            //Place the picture
            swf.Tags.Add(new PlaceObject2Tag(shapeTag.CharacterId, 1, 0, 0));
            //Add a frame
            swf.Tags.Add(new ShowFrameTag());

            for (int i = 0; i < alphaFrameNum; i++)
            {
                int percent    = (i * 100) / alphaFrameNum;
                int diff       = alphaEnd - alphaStart;
                int valPercent = (diff * percent) / 100 + alphaStart;
                int valRgb     = (255 * valPercent) / 100;
                swf.Tags.Add(new PlaceObject2Tag(1, new CXFormWithAlphaData(256, 256, 256, valRgb)));
                swf.Tags.Add(new ShowFrameTag());
            }
            swf.Tags.Add(new EndTag());

            //Write the swf to a file
            SwfWriter writer = new SwfWriter(path);

            writer.Write(swf);
            writer.Close();
            img.Dispose();
        }
示例#20
0
        static void Main(string[] args)
        {
            //Picture to transform
            string imgPath = "img.jpg";
            //string imgPath = "Untitled-1.bmp";
            //File name of the result swf file
            string path = "test.swf";

            //Load the picture to a GDI image
            Image img       = Image.FromFile(imgPath);
            int   posX      = 0;
            int   posY      = 0;
            int   imgWidth  = img.Width + 100;
            int   imgHeight = img.Height + 100;

            //Create a new Swf instance
            Swf swf = new Swf();

            swf.Size    = new Rect(0, 0, (posX + imgWidth) * 20, (posY + imgHeight) * 20);
            swf.Version = 5;

            //Set the background color tag
            swf.Tags.Add(new SetBackgroundColorTag(255, 255, 255));

            //Set the jpeg tag
            ushort jpegId = swf.GetNewDefineId();

            //Load the jped from an image
            swf.Tags.Add(DefineBitsJpeg2Tag.FromImage(jpegId, img));

            //Define the picture's shape tag
            DefineShapeTag shapeTag = new DefineShapeTag();

            shapeTag.CharacterId = swf.GetNewDefineId();
            shapeTag.Rect        = new Rect(posX * 20 - 1, posY * 20 - 1, (posX + imgWidth) * 20 - 1, (posY + imgHeight) * 20 - 1);
            FillStyleCollection fillStyles = new FillStyleCollection();

            fillStyles.Add(new BitmapFill(FillStyleType.ClippedBitmapFill, ushort.MaxValue, new Matrix(0, 0, 20, 20)));
            fillStyles.Add(new BitmapFill(FillStyleType.ClippedBitmapFill, jpegId, new Matrix(posX * 20 - 1, posY * 20 - 1, (20.0 * imgWidth) / img.Width, (20.0 * imgHeight) / img.Height)));
            LineStyleCollection   lineStyles = new LineStyleCollection();
            ShapeRecordCollection shapes     = new ShapeRecordCollection();

            shapes.Add(new StyleChangeRecord(posX * 20 - 1, posY * 20 - 1, 2));
            shapes.Add(new StraightEdgeRecord(imgWidth * 20, 0));
            shapes.Add(new StraightEdgeRecord(0, imgHeight * 20));
            shapes.Add(new StraightEdgeRecord(-imgWidth * 20, 0));
            shapes.Add(new StraightEdgeRecord(0, -imgHeight * 20));
            shapes.Add(new EndShapeRecord());
            shapeTag.ShapeWithStyle = new ShapeWithStyle(fillStyles, lineStyles, shapes);
            swf.Tags.Add(shapeTag);

            //Place the picture
            swf.Tags.Add(new PlaceObject2Tag(shapeTag.CharacterId, 1, 0, 0));
            //Add a frame
            swf.Tags.Add(new ShowFrameTag());
            swf.Tags.Add(new EndTag());

            //Write the swf to a file
            SwfWriter writer = new SwfWriter(path);

            writer.Write(swf);
            writer.Close();
            img.Dispose();
        }
示例#21
0
        private void TestFile(string file)
        {
            if (log.IsInfoEnabled)
            {
                log.Info("--- " + file + " (READING)");
            }

            this.Cursor = Cursors.WaitCursor;

            Swf swf = null;

            DateTime readStart = DateTime.Now;
            DateTime readEnd;

            try
            {
                SwfReader reader = new SwfReader(file, true);
                swf = reader.ReadSwf();
                reader.Close();

                readEnd = DateTime.Now;
                TimeSpan duration = new TimeSpan(readEnd.Ticks - readStart.Ticks);
                string   min      = duration.Minutes.ToString();
                if (min.Length == 1)
                {
                    min = "0" + min;
                }
                string sec = duration.Seconds.ToString();
                if (sec.Length == 1)
                {
                    sec = "0" + sec;
                }
                string msec = duration.Milliseconds.ToString();
                if (msec.Length == 1)
                {
                    msec = "0" + msec;
                }
                string dur = min + ":" + sec + ":" + msec;

                System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] { "READ: " + file, "OK", dur }, -1);
                listViewItem1.ForeColor = Color.Black;
                this.listView1.Items.Add(listViewItem1);
                this.listView1.Refresh();
                succeded++;

                swfList.Add(swf);
            }
            catch (Exception e)
            {
                readEnd = DateTime.Now;
                TimeSpan duration = new TimeSpan(readEnd.Ticks - readStart.Ticks);
                string   min      = duration.Minutes.ToString();
                if (min.Length == 1)
                {
                    min = "0" + min;
                }
                string sec = duration.Seconds.ToString();
                if (sec.Length == 1)
                {
                    sec = "0" + sec;
                }
                string msec = duration.Milliseconds.ToString();
                if (msec.Length == 1)
                {
                    msec = "0" + msec;
                }
                string dur = min + ":" + sec + ":" + msec;

                System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] { "READ: " + file, "KO", dur }, -1);
                listViewItem1.ForeColor = Color.Red;
                this.listView1.Items.Add(listViewItem1);
                this.listView1.Refresh();
                if (log.IsErrorEnabled)
                {
                    log.Error("READING KO", e);
                }
                swfList.Add(null);
            }

            if (log.IsInfoEnabled)
            {
                log.Info("--- " + file + " (WRITING)");
            }

            readStart = DateTime.Now;
            try
            {
                string fileName = System.IO.Path.GetFileName(file);
                string path     = this.textBoxOutput.Text + fileName;

                SwfWriter writer = new SwfWriter(path);
                writer.Write(swf);
                writer.Close();

                readEnd = DateTime.Now;
                TimeSpan duration = new TimeSpan(readEnd.Ticks - readStart.Ticks);
                string   min      = duration.Minutes.ToString();
                if (min.Length == 1)
                {
                    min = "0" + min;
                }
                string sec = duration.Seconds.ToString();
                if (sec.Length == 1)
                {
                    sec = "0" + sec;
                }
                string msec = duration.Milliseconds.ToString();
                if (msec.Length == 1)
                {
                    msec = "0" + msec;
                }
                string dur = min + ":" + sec + ":" + msec;

                System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] { "WRITE: " + path, "OK", dur }, -1);
                listViewItem1.ForeColor = Color.Black;
                this.listView1.Items.Add(listViewItem1);
                this.listView1.Refresh();

                succededWrite++;
            }
            catch (Exception ee)
            {
                readEnd = DateTime.Now;
                TimeSpan duration = new TimeSpan(readEnd.Ticks - readStart.Ticks);
                string   min      = duration.Minutes.ToString();
                if (min.Length == 1)
                {
                    min = "0" + min;
                }
                string sec = duration.Seconds.ToString();
                if (sec.Length == 1)
                {
                    sec = "0" + sec;
                }
                string msec = duration.Milliseconds.ToString();
                if (msec.Length == 1)
                {
                    msec = "0" + msec;
                }
                string dur = min + ":" + sec + ":" + msec;

                if (log.IsErrorEnabled)
                {
                    log.Error("WRITING KO", ee);
                }

                System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] { "WRITE: " + file, "KO", dur }, -1);
                listViewItem1.ForeColor = Color.Red;
                this.listView1.Items.Add(listViewItem1);
                this.listView1.Refresh();
            }

            totalParsed++;
            this.Cursor = Cursors.Default;
            Result.Text = succeded.ToString() + "/" + totalParsed.ToString();
            Result.Refresh();
            WriteResult.Text = succededWrite.ToString() + "/" + totalParsed.ToString();
            WriteResult.Refresh();
        }
示例#22
0
        static void Main(string[] args)
        {
            //Picture to transform
            string imgPath = "img.jpg";
            string path    = "test_color.swf";
            //Alpha translation informations
            int colorEffectFrameNum = 20; //frame duration

            System.Drawing.Color startColor = System.Drawing.Color.Yellow;
            System.Drawing.Color endColor   = System.Drawing.Color.Black;

            //Load the picture to a GDI image
            Image img       = Image.FromFile(imgPath);
            int   posX      = 0;
            int   posY      = 0;
            int   imgWidth  = img.Width / 2;
            int   imgHeight = img.Height / 2;

            //Create a new Swf instance
            Swf swf = new Swf();

            swf.Size    = new Rect(0, 0, (posX + imgWidth) * 20, (posY + imgHeight) * 20);
            swf.Version = 5;

            //Set the background color tag
            swf.Tags.Add(new SetBackgroundColorTag(255, 255, 255));

            //Set the jpeg tag
            ushort jpegId = swf.GetNewDefineId();

            //Load the jped from an image
            swf.Tags.Add(DefineBitsJpeg2Tag.FromImage(jpegId, img));

            //Define the picture's shape tag
            DefineShapeTag shapeTag = new DefineShapeTag();

            shapeTag.CharacterId = swf.GetNewDefineId();
            shapeTag.Rect        = new Rect(posX * 20 - 1, posY * 20 - 1, (posX + imgWidth) * 20 - 1, (posY + imgHeight) * 20 - 1);
            FillStyleCollection fillStyles = new FillStyleCollection();

            fillStyles.Add(new BitmapFill(FillStyleType.ClippedBitmapFill, ushort.MaxValue, new Matrix(0, 0, 20, 20)));
            fillStyles.Add(new BitmapFill(FillStyleType.ClippedBitmapFill, jpegId, new Matrix(posX * 20 - 1, posY * 20 - 1, (20.0 * imgWidth) / img.Width, (20.0 * imgHeight) / img.Height)));
            LineStyleCollection   lineStyles = new LineStyleCollection();
            ShapeRecordCollection shapes     = new ShapeRecordCollection();

            shapes.Add(new StyleChangeRecord(posX * 20 - 1, posY * 20 - 1, 2));
            shapes.Add(new StraightEdgeRecord(imgWidth * 20, 0));
            shapes.Add(new StraightEdgeRecord(0, imgHeight * 20));
            shapes.Add(new StraightEdgeRecord(-imgWidth * 20, 0));
            shapes.Add(new StraightEdgeRecord(0, -imgHeight * 20));
            shapes.Add(new EndShapeRecord());
            shapeTag.ShapeWithStyle = new ShapeWithStyle(fillStyles, lineStyles, shapes);
            swf.Tags.Add(shapeTag);

            //Place the picture
            swf.Tags.Add(new PlaceObject2Tag(shapeTag.CharacterId, 1, 0, 0));
            //Add a frame
            swf.Tags.Add(new ShowFrameTag());

            for (int i = 0; i < colorEffectFrameNum; i++)
            {
                int red   = GetRGBValue(i, startColor.R, endColor.R, colorEffectFrameNum);
                int green = GetRGBValue(i, startColor.G, endColor.G, colorEffectFrameNum);
                int blue  = GetRGBValue(i, startColor.B, endColor.B, colorEffectFrameNum);
                int alpha = GetRGBValue(i, startColor.A, endColor.A, colorEffectFrameNum);
                swf.Tags.Add(new PlaceObject2Tag(1, new CXFormWithAlphaData(red, green, blue, alpha)));
                swf.Tags.Add(new ShowFrameTag());
            }
            swf.Tags.Add(new EndTag());

            //Write the swf to a file
            SwfWriter writer = new SwfWriter(path);

            writer.Write(swf);
            writer.Close();
            img.Dispose();
        }
示例#23
0
 protected override void WriteData(SwfWriter writer)
 {
     writer.WriteUB((uint)FrameType, 4);
     writer.WriteUB((uint)CodecId, 4);
     writer.Write(VideoPacket);
 }
示例#24
0
 public override void WriteTagData(SwfWriter writer)
 {
     writer.Write(Id.ToByteArray());
 }
示例#25
0
 public override void WriteBody(SwfWriter writer)
 {
     writer.Write(Data);
 }