Dear Masterson,
Finally, I have inserted the image into your movie clip (sprite). I have attached these three files
Source Image
image.jpg
Source SWF File
Untitled-1.swf
Output SWF File
out.swf
I have also attached the code in a text file. You can also see this code below.
I assume you understand AddImage() method, which I gave you earlier, this time I have done a little modification inside it, instead of adding a Placeobject2 in ArrayList at the very last line of code, I have removed it, I mean these lines
/Comment this line, we don't need to place the shape which contains our
//image in this PlaceObject2 tag, we will add it in our movie clip
//InnerImageTag PlaceObject2
//flashObjs.Add(new PlaceObject2(shpID, 1, 0, 0));
instead I add the shape object which contains the image inside your InnerImageTag PlaceObject2 tag. I mean this line
//now change the object id of the innerImageTag
placeobjInnerImageTag.ObjectId = shpID;
And here is code. I hope, you understand it and it will be really helpful for you.
Code
---------------------------------------------------------------------------------
static void Main(string[] args)
{
FlashContainer flash = new FlashContainer(@"d:\downloads\Untitled-1.swf");
//Find the placeobject2 tag
PlaceObject2 placeobjImageTag = null;
foreach (PlaceObject2 obj in flash.GetObjectsOfType(BaseObjectType.PlaceObject2))
{
if (obj.Name == "ImageTag")
{
placeobjImageTag = obj;
break;
}
}
//Find the definesprite corresponding to placeobject2 found above
DefineSprite defsprtImageTag = null;
foreach (DefineSprite obj in flash.GetObjectsOfType(BaseObjectType.DefineSprite))
{
if (obj.SpriteId == placeobjImageTag.ObjectId)
{
defsprtImageTag = obj;
break;
}
}
//Now search for innerImageTag in the definesprite tag found above
PlaceObject2 placeobjInnerImageTag = null;
foreach (PlaceObject2 obj in defsprtImageTag.ControlTags)
{
if (obj.Name == "InnerImageTag")
{
placeobjInnerImageTag = obj;
break;
}
}
//Get all the objects needed for adding image in swf file
int imgID = flash.NewIdentifier();
int shpID = flash.NewIdentifier();
ArrayList flashObjs = AddImage(imgID, shpID, "c:\\image.jpg", 0, 0, 1000, 1000);
//insert these objects before sprite
int spriteIdx = flash.Objects.IndexOf(defsprtImageTag);
//and add them in flash file
foreach (object obj in flashObjs)
{
flash.Objects.Insert(spriteIdx++, obj);
}
//now change the object id of the innerImageTag
placeobjInnerImageTag.ObjectId = shpID;
flash.Write(
@"c:\out.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));
//Comment this line, we don't need to place the shape which contains our
//image in this PlaceObject2 tag, we will add it in our movie clip
//InnerImageTag PlaceObject2
//flashObjs.Add(new PlaceObject2(shpID, 1, 0, 0));
return flashObjs;
}
Many Thanks and Kind Regards,
Shakeel Faiz
Support Engineer
Aspose Tyumen Team