public static void AreEqual(DefineShapeTag expected, DefineShapeTag actual) { Assert.AreEqual(expected.ShapeID, actual.ShapeID); AssertData.AreEqual(expected.ShapeBounds, actual.ShapeBounds, "ShapeBounds"); Assert.AreEqual(expected.FillStyles.Count, actual.FillStyles.Count, "FillStyles.Count"); for (var i = 0; i < expected.FillStyles.Count; i++) { var exp = expected.FillStyles[i]; var act = actual.FillStyles[i]; AssertFillStyles.AreEqual(exp, act, "FillStyles[" + i + "]"); } Assert.AreEqual(expected.LineStyles.Count, actual.LineStyles.Count, "LineStyles.Count"); for (var i = 0; i < expected.LineStyles.Count; i++) { var exp = expected.LineStyles[i]; var act = actual.LineStyles[i]; AssertShape.AreEqual(exp, act, "LineStyles[" + i + "]"); } Assert.AreEqual(expected.ShapeRecords.Count, actual.ShapeRecords.Count, "ShapeRecords.Count"); for (var i = 0; i < expected.ShapeRecords.Count; i++) { var exp = expected.ShapeRecords[i]; var act = actual.ShapeRecords[i]; AssertShape.AreEqual(exp, act, "ShapeRecords[" + i + "]"); } Assert.AreEqual(expected.RestData, actual.RestData); }
SwfTagBase ISwfTagVisitor <ISwfStreamReader, SwfTagBase> .Visit(DefineShapeTag tag, ISwfStreamReader reader) { tag.ShapeID = reader.ReadUInt16(); tag.ShapeBounds = reader.ReadRect(); reader.ReadToFillStylesRGB(tag.FillStyles, false); reader.ReadToLineStylesRGB(tag.LineStyles, false); reader.ReadToShapeRecordsRGB(tag.ShapeRecords); return(tag); }
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(); }
SwfTagData ISwfTagVisitor <ISwfStreamWriter, SwfTagData> .Visit(DefineShapeTag tag, ISwfStreamWriter writer) { writer.WriteUInt16(tag.ShapeID); writer.WriteRect(tag.ShapeBounds); writer.WriteFillStylesRGB(tag.FillStyles, false); writer.WriteLineStylesRGB(tag.LineStyles, false); writer.WriteShapeRecordsRGB(tag.ShapeRecords, new UnsignedBitsCount((uint)tag.FillStyles.Count).GetBits(), new UnsignedBitsCount((uint)tag.LineStyles.Count).GetBits()); writer.FlushBits(); return(null); }
private static DefineShapeTag GetDefineShapeTag2() { var tag = new DefineShapeTag { ShapeID = 7, ShapeBounds = new SwfRect { XMin = 0, XMax = 14560, YMin = 0, YMax = 1800 }, FillStyles = { new SolidFillStyleRGB { Color = new SwfRGB(255, 255, 255) } }, ShapeRecords = { new StyleChangeShapeRecordRGB { MoveDeltaX = 14560, MoveDeltaY = 1800, StateMoveTo = true, FillStyle1 = 1 }, new StraightEdgeShapeRecord { DeltaX = -14560, DeltaY = 0 }, new StraightEdgeShapeRecord { DeltaX = 0, DeltaY = -1800 }, new StraightEdgeShapeRecord { DeltaX = 14560, DeltaY = 0 }, new StraightEdgeShapeRecord { DeltaX = 0, DeltaY = 1800 }, new EndShapeRecord() }, }; return(tag); }
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(); }
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(); }
static SwfTagBase Create(SwfTagData tag_data) { var reader = new SwfStreamReader(tag_data.TagData); switch (tag_data.TagId) { // Display list case (int)SwfTagType.PlaceObject: return(PlaceObjectTag.Create(reader)); case (int)SwfTagType.PlaceObject2: return(PlaceObject2Tag.Create(reader)); case (int)SwfTagType.PlaceObject3: return(PlaceObject3Tag.Create(reader)); case (int)SwfTagType.RemoveObject: return(RemoveObjectTag.Create(reader)); case (int)SwfTagType.RemoveObject2: return(RemoveObject2Tag.Create(reader)); case (int)SwfTagType.ShowFrame: return(ShowFrameTag.Create(reader)); // Control case (int)SwfTagType.SetBackgroundColor: return(SetBackgroundColorTag.Create(reader)); case (int)SwfTagType.FrameLabel: return(FrameLabelTag.Create(reader)); case (int)SwfTagType.Protect: return(ProtectTag.Create(reader)); case (int)SwfTagType.End: return(EndTag.Create(reader)); case (int)SwfTagType.ExportAssets: return(ExportAssetsTag.Create(reader)); case (int)SwfTagType.ImportAssets: return(UnsupportedTag.Create(SwfTagType.ImportAssets)); case (int)SwfTagType.EnableDebugger: return(EnableDebuggerTag.Create(reader)); case (int)SwfTagType.EnableDebugger2: return(EnableDebugger2Tag.Create(reader)); case (int)SwfTagType.ScriptLimits: return(ScriptLimitsTag.Create(reader)); case (int)SwfTagType.SetTabIndex: return(UnsupportedTag.Create(SwfTagType.SetTabIndex)); case (int)SwfTagType.ImportAssets2: return(UnsupportedTag.Create(SwfTagType.ImportAssets2)); case (int)SwfTagType.SymbolClass: return(SymbolClassTag.Create(reader)); case (int)SwfTagType.Metadata: return(MetadataTag.Create(reader)); case (int)SwfTagType.DefineScalingGrid: return(UnsupportedTag.Create(SwfTagType.DefineScalingGrid)); case (int)SwfTagType.DefineSceneAndFrameLabelData: return(DefineSceneAndFrameLabelDataTag.Create(reader)); // Actions case (int)SwfTagType.DoAction: return(UnsupportedTag.Create(SwfTagType.DoAction)); case (int)SwfTagType.DoInitAction: return(UnsupportedTag.Create(SwfTagType.DoInitAction)); case (int)SwfTagType.DoABC: return(DoABCTag.Create(reader)); // Shape case (int)SwfTagType.DefineShape: return(DefineShapeTag.Create(reader)); case (int)SwfTagType.DefineShape2: return(DefineShape2Tag.Create(reader)); case (int)SwfTagType.DefineShape3: return(DefineShape3Tag.Create(reader)); case (int)SwfTagType.DefineShape4: return(DefineShape4Tag.Create(reader)); // Bitmaps case (int)SwfTagType.DefineBits: return(UnsupportedTag.Create(SwfTagType.DefineBits)); case (int)SwfTagType.JPEGTables: return(UnsupportedTag.Create(SwfTagType.JPEGTables)); case (int)SwfTagType.DefineBitsJPEG2: return(UnsupportedTag.Create(SwfTagType.DefineBitsJPEG2)); case (int)SwfTagType.DefineBitsJPEG3: return(UnsupportedTag.Create(SwfTagType.DefineBitsJPEG3)); case (int)SwfTagType.DefineBitsLossless: return(DefineBitsLosslessTag.Create(reader)); case (int)SwfTagType.DefineBitsLossless2: return(DefineBitsLossless2Tag.Create(reader)); case (int)SwfTagType.DefineBitsJPEG4: return(UnsupportedTag.Create(SwfTagType.DefineBitsJPEG4)); // Shape Morphing case (int)SwfTagType.DefineMorphShape: return(UnsupportedTag.Create(SwfTagType.DefineMorphShape)); case (int)SwfTagType.DefineMorphShape2: return(UnsupportedTag.Create(SwfTagType.DefineMorphShape2)); // Fonts and Text case (int)SwfTagType.DefineFont: return(UnsupportedTag.Create(SwfTagType.DefineFont)); case (int)SwfTagType.DefineFontInfo: return(UnsupportedTag.Create(SwfTagType.DefineFontInfo)); case (int)SwfTagType.DefineFontInfo2: return(UnsupportedTag.Create(SwfTagType.DefineFontInfo2)); case (int)SwfTagType.DefineFont2: return(UnsupportedTag.Create(SwfTagType.DefineFont2)); case (int)SwfTagType.DefineFont3: return(UnsupportedTag.Create(SwfTagType.DefineFont3)); case (int)SwfTagType.DefineFontAlignZones: return(UnsupportedTag.Create(SwfTagType.DefineFontAlignZones)); case (int)SwfTagType.DefineFontName: return(UnsupportedTag.Create(SwfTagType.DefineFontName)); case (int)SwfTagType.DefineText: return(UnsupportedTag.Create(SwfTagType.DefineText)); case (int)SwfTagType.DefineText2: return(UnsupportedTag.Create(SwfTagType.DefineText2)); case (int)SwfTagType.DefineEditText: return(UnsupportedTag.Create(SwfTagType.DefineEditText)); case (int)SwfTagType.CSMTextSettings: return(UnsupportedTag.Create(SwfTagType.CSMTextSettings)); case (int)SwfTagType.DefineFont4: return(UnsupportedTag.Create(SwfTagType.DefineFont4)); // Sounds case (int)SwfTagType.DefineSound: return(UnsupportedTag.Create(SwfTagType.DefineSound)); case (int)SwfTagType.StartSound: return(UnsupportedTag.Create(SwfTagType.StartSound)); case (int)SwfTagType.StartSound2: return(UnsupportedTag.Create(SwfTagType.StartSound2)); case (int)SwfTagType.SoundStreamHead: return(UnsupportedTag.Create(SwfTagType.SoundStreamHead)); case (int)SwfTagType.SoundStreamHead2: return(UnsupportedTag.Create(SwfTagType.SoundStreamHead2)); case (int)SwfTagType.SoundStreamBlock: return(UnsupportedTag.Create(SwfTagType.SoundStreamBlock)); // Buttons case (int)SwfTagType.DefineButton: return(UnsupportedTag.Create(SwfTagType.DefineButton)); case (int)SwfTagType.DefineButton2: return(UnsupportedTag.Create(SwfTagType.DefineButton2)); case (int)SwfTagType.DefineButtonCxform: return(UnsupportedTag.Create(SwfTagType.DefineButtonCxform)); case (int)SwfTagType.DefineButtonSound: return(UnsupportedTag.Create(SwfTagType.DefineButtonSound)); // Sprites and Movie Clips case (int)SwfTagType.DefineSprite: return(DefineSpriteTag.Create(reader)); // Video case (int)SwfTagType.DefineVideoStream: return(UnsupportedTag.Create(SwfTagType.DefineVideoStream)); case (int)SwfTagType.VideoFrame: return(UnsupportedTag.Create(SwfTagType.VideoFrame)); // Metadata case (int)SwfTagType.FileAttributes: return(FileAttributesTag.Create(reader)); case (int)SwfTagType.EnableTelemetry: return(EnableTelemetryTag.Create(reader)); case (int)SwfTagType.DefineBinaryData: return(DefineBinaryDataTag.Create(reader)); default: return(UnknownTag.Create(tag_data.TagId)); } }
/// <summary> /// Read next tag from swf input stream. /// </summary> /// <param name="version">Version.</param> /// <param name="binaryReader">Binary reader.</param> /// <param name="tagList">Tag list.</param> /// <returns></returns> internal static BaseTag ReadTag(byte version, BufferedBinaryReader binaryReader, BaseTagCollection tagList) { long posBefore = binaryReader.BaseStream.Position; RecordHeader rh = new RecordHeader(); rh.ReadData(binaryReader); int offset = (int)(binaryReader.BaseStream.Position - posBefore); binaryReader.BaseStream.Position = posBefore; BaseTag resTag = null; switch (rh.TagCode) { case (int)TagCodeEnum.DefineBits: resTag = new DefineBitsTag(); break; case (int)TagCodeEnum.DefineBitsJpeg2: resTag = new DefineBitsJpeg2Tag(); break; case (int)TagCodeEnum.DefineBitsJpeg3: resTag = new DefineBitsJpeg3Tag(); break; case (int)TagCodeEnum.DefineBitsLossLess: resTag = new DefineBitsLossLessTag(); break; case (int)TagCodeEnum.DefineBitsLossLess2: resTag = new DefineBitsLossLess2Tag(); break; case (int)TagCodeEnum.DefineButton: resTag = new DefineButtonTag(); break; case (int)TagCodeEnum.DefineButton2: resTag = new DefineButton2Tag(); break; case (int)TagCodeEnum.DefineButtonCxForm: resTag = new DefineButtonCxFormTag(); break; case (int)TagCodeEnum.DefineButtonSound: resTag = new DefineButtonSoundTag(); break; case (int)TagCodeEnum.DefineEditText: resTag = new DefineEditTextTag(); break; case (int)TagCodeEnum.DefineFont: resTag = new DefineFontTag(); break; case (int)TagCodeEnum.DefineFont2: resTag = new DefineFont2Tag(); break; case (int)TagCodeEnum.DefineFontInfo: resTag = new DefineFontInfoTag(); break; case (int)TagCodeEnum.DefineFontInfo2: resTag = new DefineFontInfo2Tag(); break; case (int)TagCodeEnum.DefineMorphShape: resTag = new DefineMorphShapeTag(); break; case (int)TagCodeEnum.DefineShape: resTag = new DefineShapeTag(); break; case (int)TagCodeEnum.DefineShape2: resTag = new DefineShape2Tag(); break; case (int)TagCodeEnum.DefineShape3: resTag = new DefineShape3Tag(); break; case (int)TagCodeEnum.DefineSound: resTag = new DefineSoundTag(); break; case (int)TagCodeEnum.DefineSprite: resTag = new DefineSpriteTag(); break; case (int)TagCodeEnum.DefineText: resTag = new DefineTextTag(); break; case (int)TagCodeEnum.DefineText2: resTag = new DefineText2Tag(); break; case (int)TagCodeEnum.DefineVideoStream: resTag = new DefineVideoStreamTag(); break; case (int)TagCodeEnum.DoAction: resTag = new DoActionTag(); break; case (int)TagCodeEnum.EnableDebugger: resTag = new EnableDebuggerTag(); break; case (int)TagCodeEnum.EnableDebugger2: resTag = new EnableDebugger2Tag(); break; case (int)TagCodeEnum.End: resTag = new EndTag(); break; case (int)TagCodeEnum.ExportAssets: resTag = new ExportAssetsTag(); break; case (int)TagCodeEnum.FrameLabel: resTag = new FrameLabelTag(); break; case (int)TagCodeEnum.ImportAssets: resTag = new ImportAssetsTag(); break; case (int)TagCodeEnum.InitAction: resTag = new InitActionTag(); break; case (int)TagCodeEnum.JpegTable: resTag = new JpegTableTag(); break; case (int)TagCodeEnum.PlaceObject: resTag = new PlaceObjectTag(); break; case (int)TagCodeEnum.PlaceObject2: resTag = new PlaceObject2Tag(); break; case (int)TagCodeEnum.Protect: resTag = new ProtectTag(); break; case (int)TagCodeEnum.RemoveObject: resTag = new RemoveObjectTag(); break; case (int)TagCodeEnum.RemoveObject2: resTag = new RemoveObject2Tag(); break; case (int)TagCodeEnum.ScriptLimit: resTag = new ScriptLimitTag(); break; case (int)TagCodeEnum.SetBackgroundColor: resTag = new SetBackgroundColorTag(); break; case (int)TagCodeEnum.SetTabIndex: resTag = new SetTabIndexTag(); break; case (int)TagCodeEnum.ShowFrame: resTag = new ShowFrameTag(); break; case (int)TagCodeEnum.SoundStreamBlock: resTag = new SoundStreamBlockTag(); break; case (int)TagCodeEnum.SoundStreamHead: resTag = new SoundStreamHeadTag(); break; case (int)TagCodeEnum.SoundStreamHead2: resTag = new SoundStreamHead2Tag(); break; case (int)TagCodeEnum.StartSound: resTag = new StartSoundTag(); break; case (int)TagCodeEnum.Metadata: resTag = new MetadataTag(); break; case (int)TagCodeEnum.SymbolClass: resTag = new SymbolClassTag(); break; //TODO: Sorenson Codec case (int)TagCodeEnum.VideoFrame: resTag = ReadVideoFrameTag(binaryReader, tagList); break; default: resTag = new BaseTag(binaryReader.ReadBytes(System.Convert.ToInt32(rh.TagLength + offset)), rh.TagCode); break; } //Read the data of the current tag resTag.ReadData(version, binaryReader); //LOG long mustRead = rh.TagLength + offset; if (posBefore + mustRead != binaryReader.BaseStream.Position) { binaryReader.BaseStream.Position = posBefore + rh.TagLength + offset; if (log.IsErrorEnabled) { log.Error(Enum.GetName(TagCodeEnum.DefineBits.GetType(), rh.TagCode) + "....KO"); } } else if (log.IsInfoEnabled) { log.Info(Enum.GetName(TagCodeEnum.DefineBits.GetType(), rh.TagCode) + "....OK (" + mustRead + ")"); } return(resTag); }
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(); }
ITagFormatter ISwfTagVisitor <object, ITagFormatter> .Visit(DefineShapeTag tag, object arg) { return(new DefineShapeTagFormatter()); }
/// <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); } }
private void ParseDefineShapeTag(DefineShapeTag tag) { ParseShapeWithStyle(tag.Shapes); }
public SwfDisplayList Visit(DefineShapeTag tag, SwfDisplayList dl) { AddShapesToLibrary(tag.ShapeId, tag.Shapes); return(dl); }
private static DefineShapeTag GetDefineShapeTag2() { var tag = new DefineShapeTag { ShapeID = 7, ShapeBounds = new SwfRect { XMin = 0, XMax = 14560, YMin = 0, YMax = 1800 }, FillStyles = { new SolidFillStyleRGB { Color = new SwfRGB(255, 255, 255) } }, ShapeRecords = { new StyleChangeShapeRecordRGB { MoveDeltaX = 14560, MoveDeltaY = 1800, StateMoveTo = true, FillStyle1 = 1 }, new StraightEdgeShapeRecord {DeltaX = -14560, DeltaY = 0 }, new StraightEdgeShapeRecord { DeltaX = 0, DeltaY = -1800 }, new StraightEdgeShapeRecord { DeltaX = 14560, DeltaY = 0}, new StraightEdgeShapeRecord { DeltaX = 0, DeltaY = 1800}, new EndShapeRecord() }, }; return tag; }