none
SwfDotNet library 如何才能保存多张图片在同一个SWF文件里面啊。 RRS feed

全部回复

  • namespace 将JPEG转换成SWF
     {
         partial class Form1
         {
             /// <summary>
             /// 必需的设计器变量。
             /// </summary>
             private System.ComponentModel.IContainer components = null;
     
            /// <summary>
             /// 清理所有正在使用的资源。
             /// </summary>
             /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
             protected override void Dispose(bool disposing)
             {
                 if (disposing && (components != null))
                 {
                     components.Dispose();
                 }
                 base.Dispose(disposing);
             }
     
            #region Windows 窗体设计器生成的代码
     
            /// <summary>
             /// 设计器支持所需的方法 - 不要
             /// 使用代码编辑器修改此方法的内容。
             /// </summary>
             private void InitializeComponent()
             {
                 this.label1 = new System.Windows.Forms.Label();
                 this.label2 = new System.Windows.Forms.Label();
                 this.textBox1 = new System.Windows.Forms.TextBox();
                 this.textBox2 = new System.Windows.Forms.TextBox();
                 this.button1 = new System.Windows.Forms.Button();
                 this.button2 = new System.Windows.Forms.Button();
                 this.button3 = new System.Windows.Forms.Button();
                 this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
                 this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
                 this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
                 this.SuspendLayout();
                 // 
                // label1
                 // 
                this.label1.AutoSize = true;
                 this.label1.Location = new System.Drawing.Point(30, 30);
                 this.label1.Name = "label1";
                 this.label1.Size = new System.Drawing.Size(65, 12);
                 this.label1.TabIndex = 0;
                 this.label1.Text = "文件路径:";
                 // 
                // label2
                 // 
                this.label2.AutoSize = true;
                 this.label2.Location = new System.Drawing.Point(30, 64);
                 this.label2.Name = "label2";
                 this.label2.Size = new System.Drawing.Size(65, 12);
                 this.label2.TabIndex = 1;
                 this.label2.Text = "输出路径:";
                 // 
                // textBox1
                 // 
                this.textBox1.Location = new System.Drawing.Point(102, 27);
                 this.textBox1.Name = "textBox1";
                 this.textBox1.ReadOnly = true;
                 this.textBox1.Size = new System.Drawing.Size(301, 21);
                 this.textBox1.TabIndex = 2;
                 // 
                // textBox2
                 // 
                this.textBox2.Location = new System.Drawing.Point(102, 61);
                 this.textBox2.Name = "textBox2";
                 this.textBox2.ReadOnly = true;
                 this.textBox2.Size = new System.Drawing.Size(301, 21);
                 this.textBox2.TabIndex = 3;
                 // 
                // button1
                 // 
                this.button1.Location = new System.Drawing.Point(422, 25);
                 this.button1.Name = "button1";
                 this.button1.Size = new System.Drawing.Size(75, 23);
                 this.button1.TabIndex = 4;
                 this.button1.Text = "选择";
                 this.button1.UseVisualStyleBackColor = true;
                 this.button1.Click += new System.EventHandler(this.button1_Click);
                 // 
                // button2
                 // 
                this.button2.Location = new System.Drawing.Point(422, 59);
                 this.button2.Name = "button2";
                 this.button2.Size = new System.Drawing.Size(75, 23);
                 this.button2.TabIndex = 5;
                 this.button2.Text = "选择";
                 this.button2.UseVisualStyleBackColor = true;
                 this.button2.Click += new System.EventHandler(this.button2_Click);
                 // 
                // button3
                 // 
                this.button3.Location = new System.Drawing.Point(529, 25);
                 this.button3.Name = "button3";
                 this.button3.Size = new System.Drawing.Size(75, 23);
                 this.button3.TabIndex = 6;
                 this.button3.Text = "开始转换";
                 this.button3.UseVisualStyleBackColor = true;
                 this.button3.Click += new System.EventHandler(this.button3_Click);
                 // 
                // openFileDialog1
                 // 
                this.openFileDialog1.FileName = "openFileDialog1";
                 // 
                // Form1
                 // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                 this.ClientSize = new System.Drawing.Size(616, 273);
                 this.Controls.Add(this.button3);
                 this.Controls.Add(this.button2);
                 this.Controls.Add(this.button1);
                 this.Controls.Add(this.textBox2);
                 this.Controls.Add(this.textBox1);
                 this.Controls.Add(this.label2);
                 this.Controls.Add(this.label1);
                 this.Name = "Form1";
                 this.Text = "Form1";
                 this.ResumeLayout(false);
                 this.PerformLayout();
     
            }
     
            #endregion
     
            private System.Windows.Forms.Label label1;
             private System.Windows.Forms.Label label2;
             private System.Windows.Forms.TextBox textBox1;
             private System.Windows.Forms.TextBox textBox2;
             private System.Windows.Forms.Button button1;
             private System.Windows.Forms.Button button2;
             private System.Windows.Forms.Button button3;
             private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
             private System.Windows.Forms.OpenFileDialog openFileDialog1;
             private System.Windows.Forms.SaveFileDialog saveFileDialog1;
         }
     }
    

     


    • 已编辑 彭123 2013年3月15日 8:01
    2013年3月15日 8:00
  • using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    using log4net;
    using SwfDotNet.IO;
    using SwfDotNet.IO.Tags;
    using SwfDotNet.IO.Tags.Types;
    namespace 将JPEG转换成SWF
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                string currentPath = Directory.GetCurrentDirectory();//获取应用程序的目录
                if (currentPath.EndsWith(Path.DirectorySeparatorChar.ToString()) == false)
                {
                    currentPath += Path.DirectorySeparatorChar;
                }
                string input = currentPath + "input\\sunset.jpg";
                string output = currentPath + "output\\";// + 
                this.textBox1.Text = input;
                this.textBox2.Text = output;
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                if (File.Exists(textBox1.Text))
                {
                    if (Directory.Exists(textBox2.Text))
                    {
                        try
                        {
                            string jpegFileName = textBox1.Text.Trim();
                            string outputSwfFileName = textBox2.Text + Guid.NewGuid() + ".swf";
    
                            //首次加载图片用System.DRawing.Image
                            Image img = Image.FromFile(jpegFileName);
                            int posX = 0;
                            int posY = 0;
                            int imgWidth = img.Width;
                            int imgHeight = img.Height;
    
                            //创建一个新实例
                            Swf swf = new Swf();
                            //设置大小用英寸(1 英寸 = 20 像素)
                            swf.Size = new Rect(0, 0, (posX + imgWidth) * 20, (posY + imgHeight) * 20);
                            swf.Version = 7;    //SWF版本 7 (如果要压缩,必须要大于版本5)
                            swf.Header.Signature = "CWS";   //设置签名用于压缩SWF
                            //标记的背景颜色设置为白色
                            swf.Tags.Add(new SetBackgroundColorTag(255, 255, 255));
                            //设置jpeg标签
                            ushort jpegId = swf.GetNewDefineId();
                            //直接从从图像中加载JPED
                            //事实上,这条代码只是将加载的jpeg文件作为库中的数据元素
                            swf.Tags.Add(DefineBitsJpeg2Tag.FromImage(jpegId, img));
    
                            //现在我们将定义图片的形状标记
                            //定义图片的所有转换(如旋转、色彩效果等。)
                            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);
    
                            //将图片放在屏幕上的第一层。
                            swf.Tags.Add(new PlaceObject2Tag(shapeTag.CharacterId, 1, 0, 0));                                                                  
                            //添加单个帧
                            swf.Tags.Add(new ShowFrameTag());
                            swf.Tags.Add(new EndTag());
    
                            //将swf写入文件
                            SwfWriter writer = new SwfWriter(outputSwfFileName);
                            writer.Write(swf);
                            writer.Close();
    
                            img.Dispose();
    
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                    else
                    {
                        MessageBox.Show("保存路径不存在");
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("文件不存在");
                    return;
                }
                MessageBox.Show("转换成功");
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                DialogResult res = this.openFileDialog1.ShowDialog();
                if (res == DialogResult.OK)
                {
                    if (File.Exists(this.openFileDialog1.FileName))
                        this.textBox1.Text = this.openFileDialog1.FileName;
                }
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                DialogResult res = this.folderBrowserDialog1.ShowDialog();
                if (res == DialogResult.OK)
                {
                    if (Directory.Exists(this.folderBrowserDialog1.SelectedPath))
                    {
                        this.textBox2.Text = this.folderBrowserDialog1.SelectedPath;
                    }
                }
            }
        }
    }
    

    2013年3月15日 8:01
  • Hi 彭123,

    关于SwfDotNet library相关的问题请使用以下论坛,谢谢。

    http://sourceforge.net/projects/swfdotnet/forums/forum/519041

    Bob Shen
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2013年3月18日 7:35