Here is the code that replaces the image with new image.
The code reads a source swf file namely sourcePictures.swf. This source file contains three images as movie clip with the name mov1, mov2 and mov3.
Then the code looks for the PlaceObject2 tag corresponding to mov2. After finding it, it deletes this tag and adds a new image namely c:\image.jpg at the index of this tag.
Finally, it writes the output presentation namely outPictures.swf
I have attached the source and output swf files alongwith the code and image used to replace it. Please view them.
CODE:
*********************************************
static void ReplaceImage()
{
FlashContainer flash = new FlashContainer("c:\\sourcePictures.swf");
//Replace the second picture with new image
PlaceObject2 placeObj=null;
foreach (PlaceObject2 obj in flash.GetObjectsOfType(BaseObjectType.PlaceObject2))
{
if (obj.Name == "mov2")
{
placeObj = obj
as PlaceObject2;
break;
}
}
//delete PlaceObject2 tag corresponding to this "mov2"
int mov2Idx = 0;
foreach (object obj in flash.Objects)
{
if(obj==placeObj)
break;
mov2Idx++;
}
flash.Objects.RemoveAt(mov2Idx);
//Get all the objects needed for adding image in swf file
ArrayList flashObjs = AddImage(flash.NewIdentifier(), flash.NewIdentifier(), "c:\\image.jpg", 500, 500, 5000, 3000);
//and add them at the index of deleted PlaceObject2 tag
for(int i=0, j=mov2Idx ; i<flashObjs.Count; i++, j++)
{
flash.Objects.Insert(j, flashObjs[i]);
}
//Write the output swf on disk
flash.Write(
"c:\\outPictures.swf");
}
static ArrayList AddImage(int imgID, int shpID, string imageFile, int X, int Y, int Width, int Height)
{
ArrayList flashObjs = new ArrayList();
//int imgID = flash.NewIdentifier();
FlashBitmap bmp = new FlashBitmap(imgID, FlashBitmapType.FlashBitmapJpeg, false, imageFile);
flashObjs.Add(bmp);
//Calculate scaling factor
double scaleX = ((double)Width) / (double)bmp.Width;
double scaleY = ((double)Height) / (double)bmp.Height;
//Create a rectangle shape with image as a fill via ShapeManager
ShapeManager shapeManager = new ShapeManager();
shapeManager.Add(
new SolidLine(1, new RGB(255, 0, 0, 255)));
shapeManager.Add(
new BitmapFill(FillStyleType.NonSmoothedClippedBitmap, imgID, new MatrixTransform(X, Y, scaleX, scaleY)));
shapeManager.DrawRectangle(X, Y, Width, Height);
//int identifier = flash.NewIdentifier();
//int depth = 1;
//Add the shape and place it on display list
flashObjs.Add(shapeManager.GetDefineShape(shpID));
flashObjs.Add(
new PlaceObject2(shpID, 1, 0, 0));
return flashObjs;
}
Many Thanks and Kind Regards,
Shakeel Faiz
Support Engineer
Aspose Tyumen Team