Close() public method

Closes the opened writted stream
public Close ( ) : void
return void
Exemplo n.º 1
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();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //Picture to transform
            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;
            int imgHeight = img.Height;

            //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(DefineBitsLossLessTag.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, 20)));
            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();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            //Picture to transform
            string imgPath = "img.jpg";
            string path = "test_translation.swf";
            //Alpha translation informations
            int moveFrameNum = 20; //frame duration
            int posX = 200;
            int posY = 200;
            int endPosX = 100;
            int endposY = 50;

            //Load the picture to a GDI image
            Image img = Image.FromFile(imgPath);
            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());

            swf.Tags.Add(new PlaceObject2Tag(shapeTag.CharacterId, 1, -20 * 20, -20 * 20, true));
            //Add a frame
            swf.Tags.Add(new ShowFrameTag());

            swf.Tags.Add(new PlaceObject2Tag(shapeTag.CharacterId, 1, -60 * 20, -60 * 20, true));
            //Add a frame
            swf.Tags.Add(new ShowFrameTag());

            swf.Tags.Add(new PlaceObject2Tag(shapeTag.CharacterId, 1, -100 * 20, -100 * 20, true));
            //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();
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
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();
        }