Create SWF File from Images

public class SWFBuilder
private FlashContainer FlashFile;
public SWFBuilder()
this.FlashFile = new FlashContainer();
private void SetBasicProperties()
this.FlashFile.FrameRate = 1.0f; //Play 12 Frames/Second
this.FlashFile.FrameSize = new Rect(0, 0, this._ImagesSize.Width * 20, this._ImagesSize.Height * 20); //Frame Size in twips ( 1 pixel = 20 twips)
private void AddImage(FlashContainer flashFile, string imageFilePath, int X, int Y, Single scaleX, Single scaleY, int depth)
int ImageID;
int RectWidth;
int RectHeight;
int ShapeID;
FlashBitmap BitMapObj;
MatrixTransform MTX;
BitmapFill BitmapFillObj;
Shape ImageShape;
ArrayList FillStylesArray;
ArrayList LineStylesArray;
StyleChangeRecord SCRObject;
// ID for this image
ImageID = flashFile.NewIdentifier();
// Create FlashBitmap for this image
BitMapObj = new FlashBitmap(ImageID, FlashBitmapType.FlashBitmapJpeg, false, imageFilePath);
// Add image in flash file
#region “– Create a rectangluar shape and use the image as a fill –“
// Create matrix for the fill
// Matrix is used for transformation e.g TRANSLATION, SCALING, ROTATION
// Fill will start from position X,Y – TRANSLATION
MTX = new MatrixTransform(X, Y);
// Scale the fill ScaleX and ScaleY units – SCALING
MTX.Scale(scaleX, scaleY);
// Image fill
// For  stretched image only
// The ID of the image which is used as a fill
BitmapFillObj = new BitmapFill(FillStyleType.NonSmoothedClippedBitmap, ImageID, MTX);
// The Matrix to scale the image
// Fill Styles Array
FillStylesArray = new ArrayList();
// Add image fill inside it
// Line Styles Array,
LineStylesArray = new ArrayList();
// Rectangluar Shape
ImageShape = new Shape();
// Style Change Record (SCR) will select a fill for this shape
// It will also select the starting position. X,Y is a starting position
SCRObject = new StyleChangeRecord(X, Y);
// Select first fill from fillStyles
// which is actually an image fill
SCRObject.FillStyle = 1;
// Add the SCR to shape
// Straight Edge Records (SERs) will define rectangle
// This rectangle will start from (0,0) and … rectWidth wide and rectHeight high
// rectWidth is actually the width of image after scaling
RectWidth = Convert.ToInt32((scaleX * Convert.ToSingle(BitMapObj.Width)));
// rectHeight is actually the height of image after scaling
RectHeight = Convert.ToInt32((scaleY * Convert.ToSingle(BitMapObj.Height)));
// Move X RIGTH, don// t change Y
ImageShape.Add(new StraightEdgeRecord(RectWidth, 0));
// Move Y DOWN, don// t change X
ImageShape.Add(new StraightEdgeRecord(0, RectHeight));
// Move X left, don// t change Y
ImageShape.Add(new StraightEdgeRecord(-RectWidth, 0));
// Move Y up
ImageShape.Add(new StraightEdgeRecord(0, -RectHeight));
// Define the shape
ShapeID = flashFile.NewIdentifier();
// Create and add DefineShape
// Bounding Rectangle
// Fill Styles array, the first fill is the image fill
// Line Styles array, it does not have any line styles
// The shape which will be filled with image fill
flashFile.Add(new DefineShape(ShapeID, new Rect(X, Y, RectWidth, RectHeight), FillStylesArray, LineStylesArray, ImageShape));
// Place the shape onto Display list and set the image depth
flashFile.Add(new PlaceObject2(ShapeID, depth));
public override void GenerateFile(string outputFileNameWPath, List<string> imagesFileNameWPath)
int ImageDepth = 1;
//Create a flash container/flash file
foreach (string ImageFileNameWPath in imagesFileNameWPath)
// Add image
AddImage(this.FlashFile, ImageFileNameWPath, 0, 0, 20, 20, ImageDepth++);
//Show the images
this.FlashFile.Add(new ShowFrame());
//Write final flash on disk
Continue ReadingCreate SWF File from Images