Use of swfdotnet, multiple images generated SWF

Source: Internet
Author: User

All of a sudden to do a lot of pictures into a SWF work, and still use the unused C #, fortunately, the syntax is similar to Java, the Internet to find a circle, find a swfdotnet plug-in, the URL is as follows:

Http://www.codeproject.com/KB/graphics/jpeg2swf.aspx?fid=369197&df=90&mpp=10&noise=3&prof=True &sort=position&view=quick&fr=21

The sample code on the page, but only for a picture, do not see the effect of SWF, the following code is mostly used in the sample code, the key code I will comment on the description.

Image img = image.fromfile (jpegfilename), int posX = 0;int PosY = 0;int imgwidth = img. Width;int imgheight = img. Height;
Create a new swf instanceswf swf = new swf ();//set size in inch unit (1 Pixel = inches) swf. Size = new Rect (0, 0, (PosX + imgwidth) *, (PosY + imgheight) *), SWF.  Version = 7; //version 7 (for Compression, must be > 5) swf.  Header.signature = //set the signature to Compress the swfswf. Header.fps = 1;//How many frames per second, this is very important, after adding a number of pictures, depending on the control speed //set the background color tag as whiteswf. Tags.add (New Setbackgroundcolortag (255, 255, 255)); 
Set the jpeg tagushort jpegid = swf. Getnewdefineid (); //load the jped directly from a image//a library element only (not to display the JPEG) SWF. Tags.add (Definebitsjpeg2tag.fromimage (Jpegid, IMG)); 
Now we'll define the picture ' s shape tagTo define all the transformations in 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, a)); 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 *, 0)); shapes. ADD (New Straightedgerecord (0, ImgHeight *)); shapes. ADD (New Straightedgerecord (-imgwidth *, 0)); shapes. ADD (NEW Straightedgerecord (0,-imgheight *)); shapes. ADD (New Endshaperecord ()), Shapetag.shapewithstyle = new Shapewithstyle (fillstyles, linestyles, shapes), SWF. Tags.add (Shapetag);//place the picture to the screens with depth=1swf. Tags.add (New Placeobject2tag (Shapetag.characterid, 1, 0, 0));
Add a single frameswf. Tags.add (New Showframetag ());//This is also very important, according to the previous set of FPS parameters, 1 frames per second, more than a few frames repeated, this image can continue to display a few seconds
Swf. Tags.add (New Showframetag ());
Swf. Tags.add (New Showframetag ());//I repeat this here 3 times to show 3 seconds.
Swf. Tags.add (New Removeobject2tag (1));//This is also important, the front of the image is inserted into which layer, the layer is removed, similar to the image overlay before the kind of
The following is a second picture added
Image = System.Drawing.Image.FromFile ("2.jpg");
Imgid = swf. Getnewdefineid ();
Shapetag = new Defineshapetag ();
Shapetag.characterid = swf. Getnewdefineid ();
Shapetag.rect = new SwfDotNet.IO.Tags.Types.Rect (PosX * 20-1, PosY * 20-1, (PosX + imagewidth) * 20-1, (PosY + Imagew Idth) * 20-1);
Fillstyles = new Fillstylecollection ();
Fillstyles.add (New SwfDotNet.IO.Tags.Types.BitmapFill (Fillstyletype.clippedbitmapfill, ushort. MaxValue, New SwfDotNet.IO.Tags.Types.Matrix (0, 0, 20, 20));
Fillstyles.add (New Bitmapfill (Fillstyletype.clippedbitmapfill, Imgid, New SwfDotNet.IO.Tags.Types.Matrix (PosX * 20-1 , PosY * 20-1, (20.0 * imagewidth)/image. Width, (20.0 * imageheight)/image. Height));
Linestyles = new Linestylecollection (); Shapes = new Shaperecordcollection ();
Shapes. ADD (New Stylechangerecord (PosX * 20-1, PosY * 20-1, 2));
Shapes. ADD (New Straightedgerecord (ImageWidth * 20, 0));
Shapes. ADD (New Straightedgerecord (0, ImageHeight * 20));
Shapes. ADD (New Straightedgerecord (-imagewidth * 20, 0));
Shapes. ADD (New Straightedgerecord (0,-imageheight * 20));
Shapes. ADD (New Endshaperecord ());
Shapetag.shapewithstyle = new Shapewithstyle (fillstyles, linestyles, shapes);
Swf. Tags.add (Shapetag); Place the pictures to the screens with depth=1, set the picture in the screen depth to 1
Swf. Tags.add (New Placeobject2tag (Shapetag.characterid, 1, 0, 0));
Add a single frame
Swf. Tags.add (New Showframetag ());//The frame parameter of this and the first picture is a meaningSwf. Tags.add (New Endtag ()); //write the SWF to a fileswfwriter writer = new Swfwriter (outputswffilename); writer. Write (SWF); writer. Close (); img. Dispose ();
OK, finally put this problem solved, record, Baidu Space unexpectedly closed, record to here good!

Use of swfdotnet, multiple images generated SWF

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.