/// <summary> /// Creates a new <see cref="ShapeWithStyle"/> instance. /// </summary> /// <param name="fillStyleArray">Fill style array.</param> /// <param name="lineStyleArray">Line style array.</param> /// <param name="shapes">Shapes.</param> public ShapeWithStyle(FillStyleCollection fillStyleArray, LineStyleCollection lineStyleArray, ShapeRecordCollection shapes) { this.fillStyleArray = fillStyleArray; this.lineStyleArray = lineStyleArray; this.shapes = shapes; }
/// <summary> /// Removes the specified value. /// </summary> /// <param name="value">Value.</param> public void Remove(ShapeRecordCollection value) { if (List.Contains(value)) { List.Remove(value as object); } }
/// <summary> /// Reads the data. /// </summary> /// <param name="binaryReader">Binary reader.</param> /// <param name="numGlyphs">Num glyphs.</param> public void ReadData(BufferedBinaryReader binaryReader, ushort numGlyphs) { if (numGlyphs == 0) { return; } ShapeWithStyle.NumFillBits = 0; ShapeWithStyle.NumLineBits = 0; ShapeRecordCollection[] shapes = new ShapeRecordCollection[numGlyphs]; for (int i = 0; i < numGlyphs; i++) { ShapeRecordCollection glyphShape = new ShapeRecordCollection(); glyphShape.ReadData(binaryReader, ShapeType.None); shapes[i] = glyphShape; } for (int i = 0; i < numGlyphs; i++) { char c; if (isWideCodes) { c = (char)binaryReader.ReadUInt16(); } else { c = (char)binaryReader.ReadByte(); } this[c] = shapes[i]; } shapes = null; }
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(); }
/// <summary> /// Reads the data. /// </summary> /// <param name="reader">Reader.</param> /// <param name="numGlyphs">Num glyphs.</param> public void ReadData(BufferedBinaryReader reader, ushort numGlyphs) { for (int i = 0; i < numGlyphs; i++) { ShapeRecordCollection glyphShape = new ShapeRecordCollection(); glyphShape.ReadData(reader, ShapeType.None); this.Add(glyphShape); } }
/// <summary> /// Gets the ordered glyphs. /// </summary> /// <param name="orderedCodes">Ordered codes.</param> public ShapeRecordCollection[] GetOrderedGlyphs(char[] orderedCodes) { ShapeRecordCollection[] res = new ShapeRecordCollection[orderedCodes.Length]; IEnumerator codesEnum = orderedCodes.GetEnumerator(); for (int i = 0; codesEnum.MoveNext(); i++) { res[i] = this[(char)codesEnum.Current]; } return(res); }
/// <summary> /// Adds the range. /// </summary> /// <param name="values">Values.</param> public void AddRange(ShapeRecordCollection values) { if (values == null) { return; } IEnumerator enu = values.GetEnumerator(); while (enu.MoveNext()) { Add((ShapeRecord)enu.Current); } }
/// <summary> /// Reads the data. /// </summary> /// <param name="binaryReader">Binary reader.</param> /// <param name="shapeType">Shape type.</param> public void ReadData(BufferedBinaryReader binaryReader, ShapeType shapeType) { base.SetStartPoint(binaryReader); fillStyleArray = new FillStyleCollection(); fillStyleArray.ReadData(binaryReader, shapeType); lineStyleArray = new LineStyleCollection(); lineStyleArray.ReadData(binaryReader, shapeType); shapes = new ShapeRecordCollection(); shapes.ReadData(binaryReader, shapeType); base.SetEndPoint(binaryReader); }
/// <summary> /// Gets the glyphs size of. /// </summary> /// <returns></returns> public int GetGlyphsSizeOf() { int res = 0; ShapeWithStyle.NumFillBits = 0; ShapeWithStyle.NumLineBits = 0; IEnumerator glyphShapesCollections = this.Values.GetEnumerator(); while (glyphShapesCollections.MoveNext()) { ShapeRecordCollection glyphs = (ShapeRecordCollection)glyphShapesCollections.Current; ShapeWithStyle.NumFillBits = 1; res += glyphs.GetSizeOf(); } return(res); }
/// <summary> /// Removes the specified value. /// </summary> /// <param name="value">Value.</param> public void Remove(ShapeRecordCollection value) { if (List.Contains(value)) List.Remove(value as object); }
/// <summary> /// Creates a new <see cref="DefineMorphShapeTag"/> instance. /// </summary> /// <param name="characterId">Character id.</param> /// <param name="startBounds">Start bounds.</param> /// <param name="endBounds">End bounds.</param> /// <param name="offset">Offset.</param> /// <param name="morphFillStyles">Morph fill styles.</param> /// <param name="morphLineStyles">Morph line styles.</param> /// <param name="startEdges">Start edges.</param> /// <param name="endEdges">End edges.</param> public DefineMorphShapeTag(ushort characterId, Rect startBounds, Rect endBounds, uint offset, MorphFillStyleCollection morphFillStyles, MorphLineStyleCollection morphLineStyles, ShapeRecordCollection startEdges, ShapeRecordCollection endEdges) { this.characterId = characterId; this.startBounds = startBounds; this.endBounds = endBounds; this.offset = offset; this.morphFillStyles = morphFillStyles; this.morphLineStyles = morphLineStyles; this.startEdges = startEdges; this.endEdges = endEdges; this._tagCode = (int)TagCodeEnum.DefineMorphShape; }
/// <summary> /// Reads the data. /// </summary> /// <param name="binaryReader">Binary reader.</param> /// <param name="numGlyphs">Num glyphs.</param> public void ReadData(BufferedBinaryReader binaryReader, ushort numGlyphs) { if (numGlyphs == 0) return; ShapeWithStyle.NumFillBits = 0; ShapeWithStyle.NumLineBits = 0; ShapeRecordCollection[] shapes = new ShapeRecordCollection[numGlyphs]; for (int i = 0; i < numGlyphs; i++) { ShapeRecordCollection glyphShape = new ShapeRecordCollection(); glyphShape.ReadData(binaryReader, ShapeType.None); shapes[i] = glyphShape; } for (int i = 0; i < numGlyphs; i++) { char c; if (isWideCodes) c = (char)binaryReader.ReadUInt16(); else c = (char)binaryReader.ReadByte(); this[c] = shapes[i]; } shapes = null; }
/// <summary> /// Creates a new <see cref="ShapeRecordCollection"/> instance. /// </summary> /// <param name="shapes">Shapes.</param> public GlyphShapesCollection(ShapeRecordCollection[] shapes) { if (shapes != null) AddRange(shapes); }
/// <summary> /// Adds the specified value. /// </summary> /// <param name="value">Value.</param> /// <returns></returns> public ShapeRecordCollection Add(ShapeRecordCollection value) { List.Add(value as object); return(value); }
/// <summary> /// Inits this instance. /// </summary> private void Init() { this.fillStyleArray = new FillStyleCollection(); this.lineStyleArray = new LineStyleCollection(); this.shapes = new ShapeRecordCollection(); }
/// <summary> /// Adds the specified value. /// </summary> /// <param name="value">Value.</param> /// <returns></returns> public ShapeRecordCollection Add(ShapeRecordCollection value) { List.Add(value as object); return value; }
/// <summary> /// Inserts the specified index. /// </summary> /// <param name="index">Index.</param> /// <param name="value">Value.</param> public void Insert(int index, ShapeRecordCollection value) { List.Insert(index, value as object); }
/// <summary> /// Gets the ordered glyphs. /// </summary> /// <param name="orderedCodes">Ordered codes.</param> public ShapeRecordCollection[] GetOrderedGlyphs(char[] orderedCodes) { ShapeRecordCollection[] res = new ShapeRecordCollection[orderedCodes.Length]; IEnumerator codesEnum = orderedCodes.GetEnumerator(); for (int i = 0; codesEnum.MoveNext(); i++) res[i] = this[(char)codesEnum.Current]; return res; }
/// <summary> /// Containses the specified value. /// </summary> /// <param name="value">Value.</param> /// <returns></returns> public bool Contains(ShapeRecordCollection value) { return(List.Contains(value as object)); }
/// <summary> /// Adds the specified character. /// </summary> /// <param name="character">Character.</param> /// <param name="glyphShapes">Glyph shapes.</param> public void Add(char character, ShapeRecordCollection glyphShapes) { base.Add (character, glyphShapes); }
/// <summary> /// Get the index of. /// </summary> /// <param name="value">Value.</param> /// <returns></returns> public int IndexOf(ShapeRecordCollection value) { return(List.IndexOf(value)); }
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(); }
/// <summary> /// Containses the specified value. /// </summary> /// <param name="value">Value.</param> /// <returns></returns> public bool Contains(ShapeRecordCollection value) { return List.Contains(value as object); }
/// <summary> /// Adds the specified character. /// </summary> /// <param name="character">Character.</param> /// <param name="glyphShapes">Glyph shapes.</param> public void Add(char character, ShapeRecordCollection glyphShapes) { base.Add(character, glyphShapes); }
/// <summary> /// Get the index of. /// </summary> /// <param name="value">Value.</param> /// <returns></returns> public int IndexOf(ShapeRecordCollection value) { return List.IndexOf(value); }
/// <summary> /// Adds the range. /// </summary> /// <param name="values">Values.</param> public void AddRange(ShapeRecordCollection values) { if (values == null) return; IEnumerator enu = values.GetEnumerator(); while (enu.MoveNext()) Add((ShapeRecord)enu.Current); }
/// <summary> /// see <see cref="SwfDotNet.IO.Tags.BaseTag">base class</see> /// </summary> public override void ReadData(byte version, BufferedBinaryReader binaryReader) { RecordHeader rh = new RecordHeader(); rh.ReadData(binaryReader); characterId = binaryReader.ReadUInt16(); binaryReader.SynchBits(); startBounds = new Rect(); startBounds.ReadData(binaryReader); binaryReader.SynchBits(); endBounds = new Rect(); endBounds.ReadData(binaryReader); binaryReader.SynchBits(); offset = binaryReader.ReadUInt32(); morphFillStyles = new MorphFillStyleCollection(); morphFillStyles.ReadData(binaryReader); morphLineStyles = new MorphLineStyleCollection(); morphLineStyles.ReadData(binaryReader); ShapeWithStyle.NumFillBits = (uint)morphFillStyles.Count; ShapeWithStyle.NumLineBits = (uint)morphLineStyles.Count; startEdges = new ShapeRecordCollection(); startEdges.ReadData(binaryReader, ShapeType.None); ShapeWithStyle.NumFillBits = (uint)morphFillStyles.Count; ShapeWithStyle.NumLineBits = (uint)morphLineStyles.Count; endEdges = new ShapeRecordCollection(); endEdges.ReadData(binaryReader, ShapeType.None); }
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(); }