利用C#实现批量图片格式转换功能

目录
  • 实践过程
    • 效果
    • 代码

实践过程

效果

代码

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    string[] path1 = null; //用于存储选择的文件列表
    string path2 = ""; //用于存储保存的路径
    Bitmap bt; //声明一个转换图片格式的Bitmap对象
    Thread td; //声明一个线程
    int Imgtype1; //声明一个变量用于标记ConvertImage方法中转换的类型
    string OlePath; //声明一个变量用于存储ConvertImage方法中原始图片的路径
    string path; //声明一个变量用于存储ConvertImage方法中转换后图片的保存路径
    int flags; //用于标记已转换图片的数量,用于计算转换进度

    private void Form2_Load(object sender, EventArgs e)
    {
        tscbType.SelectedIndex = 0; //设置第一个转换类型被选中
        CheckForIllegalCrossThreadCalls = false; //屏蔽线程弹出的错误提示
    }

    private void toolStripButton3_Click(object sender, EventArgs e) //选择转换文件的按钮
    {
        if (openFileDialog1.ShowDialog() == DialogResult.OK) //判断是否选择文件
        {
            listView1.Items.Clear(); //清空listView1
            string[] info = new string[7]; //存储每一行数据
            FileInfo fi; //创建一个FileInfo对象,用于获取图片信息
            path1 = openFileDialog1.FileNames; //获取选择的图片集合
            for (int i = 0; i < path1.Length; i++) //读取集合中的内容
            {
                //获取图片名称
                string ImgName = path1[i].Substring(path1[i].LastIndexOf("\\") + 1,
                    path1[i].Length - path1[i].LastIndexOf("\\") - 1);
                //获取图片类型
                string ImgType = ImgName.Substring(ImgName.LastIndexOf(".") + 1,
                    ImgName.Length - ImgName.LastIndexOf(".") - 1);
                fi = new FileInfo(path1[i].ToString()); //实例化FileInfo对象
                //将每一行数据第一个位置的图标添加到imageList1中
                imageList1.Images.Add(ImgName, Properties.Resources.图标__23_);
                info[1] = ImgName; //图片名称
                info[2] = ImgType; //图片类型
                info[3] = fi.LastWriteTime.ToShortDateString(); //图片最后修改日期
                info[4] = path1[i].ToString(); //图片位置
                info[5] = (fi.Length / 1024) + "KB"; //图片大小
                info[6] = "未转换"; //图片状态
                ListViewItem lvi = new ListViewItem(info, ImgName); //实例化ListViewItem对象
                listView1.Items.Add(lvi); //将信息添加到listView1控件中
            }

            tsslFileNum.Text = "当前共有" + path1.Length.ToString() + "个文件"; //状态栏中显示图片数量
        }
    }

    private void toolStripButton2_Click(object sender, EventArgs e) //关闭按钮
    {
        Application.Exit(); //退出系统
    }

    private void toolStripButton5_Click(object sender, EventArgs e) //清空列表的按钮
    {
        listView1.Items.Clear(); //清空列表
        path1 = null; //清空图片的集合
        tsslFileNum.Text = "当前没有文件"; //状态栏中提示
        tsslPlan.Text = ""; //清空进度数字
    }

    private void toolStripButton1_Click(object sender, EventArgs e)
    {
        if (path1 == null) //判断是否选择图片
        {
            MessageBox.Show("请选择图片!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        else
        {
            if (path2.Length == 0) //判断是否选择保存位置
            {
                MessageBox.Show("请选择保存位置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                flags = 1; //初始化flags变量为1,用于计算进度
                toolStrip1.Enabled = false; //当转换开始时,禁用工具栏
                int flag = tscbType.SelectedIndex; //判断将图片转换为何种格式
                switch (flag) //根据不同的格式进行转换
                {
                    case 0:
                        Imgtype1 = 0; //如果选择第一项则转换为BMP格式
                        td = new Thread(new ThreadStart(ConvertImage)); //通过线程调用ConvertImage方法进行转换
                        td.Start();
                        break;
                    case 1: //如果选择第二项则转换为JPG格式
                        Imgtype1 = 1;
                        td = new Thread(new ThreadStart(ConvertImage)); //通过线程调用ConvertImage方法进行转换
                        td.Start();
                        break;
                    case 2: //如果选择第三项则转换为PNG格式
                        Imgtype1 = 2;
                        td = new Thread(new ThreadStart(ConvertImage)); //通过线程调用ConvertImage方法进行转换
                        td.Start();
                        break;
                    case 3: //如果选择第四项则转换为GIF格式
                        Imgtype1 = 3;
                        td = new Thread(new ThreadStart(ConvertImage)); //通过线程调用ConvertImage方法进行转换
                        td.Start();
                        break;
                    default:
                        td.Abort();
                        break;
                }
            }
        }
    }

    private void toolStripButton4_Click(object sender, EventArgs e) //选择保存路径按钮
    {
        if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) //判断是否选择保存路径
        {
            path2 = folderBrowserDialog1.SelectedPath; //获取保存路径
        }
    }

    private void ConvertImage()
    {
        flags = 1;
        switch (Imgtype1)
        {
            case 0:
                for (int i = 0; i < path1.Length; i++)
                {
                    string ImgName = path1[i].Substring(path1[i].LastIndexOf("\\") + 1,
                        path1[i].Length - path1[i].LastIndexOf("\\") - 1);
                    ImgName = ImgName.Remove(ImgName.LastIndexOf("."));
                    OlePath = path1[i].ToString();
                    bt = new Bitmap(OlePath);
                    path = path2 + "\\" + ImgName + ".bmp";
                    bt.Save(path, System.Drawing.Imaging.ImageFormat.Bmp);
                    listView1.Items[flags - 1].SubItems[6].Text = "已转换";
                    tsslPlan.Text = "正在转换" + flags * 100 / path1.Length + "%";
                    if (flags == path1.Length)
                    {
                        toolStrip1.Enabled = true;
                        tsslPlan.Text = "图片转换全部完成";
                    }

                    flags++;
                }

                break;
            case 1:
                for (int i = 0; i < path1.Length; i++)
                {
                    string ImgName = path1[i].Substring(path1[i].LastIndexOf("\\") + 1,
                        path1[i].Length - path1[i].LastIndexOf("\\") - 1);
                    ImgName = ImgName.Remove(ImgName.LastIndexOf("."));
                    OlePath = path1[i].ToString();
                    bt = new Bitmap(OlePath);
                    path = path2 + "\\" + ImgName + ".jpeg";
                    bt.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
                    listView1.Items[flags - 1].SubItems[6].Text = "已转换";
                    tsslPlan.Text = "正在转换" + flags * 100 / path1.Length + "%";
                    if (flags == path1.Length)
                    {
                        toolStrip1.Enabled = true;
                        tsslPlan.Text = "图片转换全部完成";
                    }

                    flags++;
                }

                break;
            case 2:
                for (int i = 0; i < path1.Length; i++)
                {
                    string ImgName = path1[i].Substring(path1[i].LastIndexOf("\\") + 1,
                        path1[i].Length - path1[i].LastIndexOf("\\") - 1);
                    ImgName = ImgName.Remove(ImgName.LastIndexOf("."));
                    OlePath = path1[i].ToString();
                    bt = new Bitmap(OlePath);
                    path = path2 + "\\" + ImgName + ".png";
                    bt.Save(path, System.Drawing.Imaging.ImageFormat.Png);
                    listView1.Items[flags - 1].SubItems[6].Text = "已转换";
                    tsslPlan.Text = "正在转换" + flags * 100 / path1.Length + "%";
                    if (flags == path1.Length)
                    {
                        toolStrip1.Enabled = true;
                        tsslPlan.Text = "图片转换全部完成";
                    }

                    flags++;
                }

                break;
            case 3:
                for (int i = 0; i < path1.Length; i++)
                {
                    string ImgName = path1[i].Substring(path1[i].LastIndexOf("\\") + 1,
                        path1[i].Length - path1[i].LastIndexOf("\\") - 1);
                    ImgName = ImgName.Remove(ImgName.LastIndexOf("."));
                    OlePath = path1[i].ToString();
                    bt = new Bitmap(OlePath);
                    path = path2 + "\\" + ImgName + ".gif";
                    bt.Save(path, System.Drawing.Imaging.ImageFormat.Gif);
                    listView1.Items[flags - 1].SubItems[6].Text = "已转换";
                    tsslPlan.Text = "正在转换" + flags * 100 / path1.Length + "%";
                    if (flags == path1.Length)
                    {
                        toolStrip1.Enabled = true;
                        tsslPlan.Text = "图片转换全部完成";
                    }

                    flags++;
                }

                break;
            default:
                bt.Dispose();
                break;
        }
    }

    private void Form2_FormClosed(object sender, FormClosedEventArgs e) //关闭窗口时要关闭线程
    {
        if (td != null) //判断是否存在线程
        {
            if (td.ThreadState == ThreadState.Running) //然后判断线程是否正在运行
            {
                td.Abort(); //如果运行则关闭线程
            }
        }
    }
}
partial class Form1
{
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.components = new System.ComponentModel.Container();
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
        this.toolStrip1 = new System.Windows.Forms.ToolStrip();
        this.toolStripLabel1 = new System.Windows.Forms.ToolStripLabel();
        this.toolStripButton3 = new System.Windows.Forms.ToolStripButton();
        this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
        this.toolStripButton4 = new System.Windows.Forms.ToolStripButton();
        this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
        this.toolStripLabel3 = new System.Windows.Forms.ToolStripLabel();
        this.tscbType = new System.Windows.Forms.ToolStripComboBox();
        this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
        this.toolStripButton1 = new System.Windows.Forms.ToolStripButton();
        this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
        this.toolStripButton5 = new System.Windows.Forms.ToolStripButton();
        this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator();
        this.toolStripButton2 = new System.Windows.Forms.ToolStripButton();
        this.statusStrip1 = new System.Windows.Forms.StatusStrip();
        this.tsslFileNum = new System.Windows.Forms.ToolStripStatusLabel();
        this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
        this.tsslPlan = new System.Windows.Forms.ToolStripStatusLabel();
        this.listView1 = new System.Windows.Forms.ListView();
        this.columnHeader6 = new System.Windows.Forms.ColumnHeader();
        this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
        this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
        this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
        this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
        this.columnHeader5 = new System.Windows.Forms.ColumnHeader();
        this.columnHeader7 = new System.Windows.Forms.ColumnHeader();
        this.imageList1 = new System.Windows.Forms.ImageList(this.components);
        this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
        this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
        this.toolStrip1.SuspendLayout();
        this.statusStrip1.SuspendLayout();
        this.SuspendLayout();
        //
        // toolStrip1
        //
        this.toolStrip1.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
        this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
        this.toolStripLabel1,
        this.toolStripButton3,
        this.toolStripSeparator1,
        this.toolStripButton4,
        this.toolStripSeparator2,
        this.toolStripLabel3,
        this.tscbType,
        this.toolStripSeparator3,
        this.toolStripButton1,
        this.toolStripSeparator4,
        this.toolStripButton5,
        this.toolStripSeparator5,
        this.toolStripButton2});
        this.toolStrip1.Location = new System.Drawing.Point(0, 0);
        this.toolStrip1.Name = "toolStrip1";
        this.toolStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;
        this.toolStrip1.Size = new System.Drawing.Size(536, 25);
        this.toolStrip1.TabIndex = 0;
        this.toolStrip1.Text = "toolStrip1";
        //
        // toolStripLabel1
        //
        this.toolStripLabel1.Name = "toolStripLabel1";
        this.toolStripLabel1.Size = new System.Drawing.Size(17, 22);
        this.toolStripLabel1.Text = "  ";
        //
        // toolStripButton3
        //
        this.toolStripButton3.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
        this.toolStripButton3.Image = global::PictureBatchConversion.Properties.Resources.打开;
        this.toolStripButton3.ImageTransparentColor = System.Drawing.Color.Magenta;
        this.toolStripButton3.Name = "toolStripButton3";
        this.toolStripButton3.Size = new System.Drawing.Size(23, 22);
        this.toolStripButton3.Text = "toolStripButton3";
        this.toolStripButton3.ToolTipText = "选择需要转换的图片";
        this.toolStripButton3.Click += new System.EventHandler(this.toolStripButton3_Click);
        //
        // toolStripSeparator1
        //
        this.toolStripSeparator1.Name = "toolStripSeparator1";
        this.toolStripSeparator1.Size = new System.Drawing.Size(6, 25);
        //
        // toolStripButton4
        //
        this.toolStripButton4.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
        this.toolStripButton4.Image = global::PictureBatchConversion.Properties.Resources.图标__29_;
        this.toolStripButton4.ImageTransparentColor = System.Drawing.Color.Magenta;
        this.toolStripButton4.Name = "toolStripButton4";
        this.toolStripButton4.Size = new System.Drawing.Size(23, 22);
        this.toolStripButton4.Text = "toolStripButton4";
        this.toolStripButton4.TextImageRelation = System.Windows.Forms.TextImageRelation.Overlay;
        this.toolStripButton4.ToolTipText = "选择保存位置";
        this.toolStripButton4.Click += new System.EventHandler(this.toolStripButton4_Click);
        //
        // toolStripSeparator2
        //
        this.toolStripSeparator2.Name = "toolStripSeparator2";
        this.toolStripSeparator2.Size = new System.Drawing.Size(6, 25);
        //
        // toolStripLabel3
        //
        this.toolStripLabel3.Name = "toolStripLabel3";
        this.toolStripLabel3.Size = new System.Drawing.Size(65, 22);
        this.toolStripLabel3.Text = "转换格式:";
        //
        // tscbType
        //
        this.tscbType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
        this.tscbType.FlatStyle = System.Windows.Forms.FlatStyle.System;
        this.tscbType.Items.AddRange(new object[] {
        "转换为BMP格式",
        "转换为JPG格式",
        "转换为PNG格式",
        "转换为GIF格式"});
        this.tscbType.Name = "tscbType";
        this.tscbType.Size = new System.Drawing.Size(121, 25);
        //
        // toolStripSeparator3
        //
        this.toolStripSeparator3.Name = "toolStripSeparator3";
        this.toolStripSeparator3.Size = new System.Drawing.Size(6, 25);
        //
        // toolStripButton1
        //
        this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
        this.toolStripButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton1.Image")));
        this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
        this.toolStripButton1.Name = "toolStripButton1";
        this.toolStripButton1.Size = new System.Drawing.Size(57, 22);
        this.toolStripButton1.Text = "开始转换";
        this.toolStripButton1.Click += new System.EventHandler(this.toolStripButton1_Click);
        //
        // toolStripSeparator4
        //
        this.toolStripSeparator4.Name = "toolStripSeparator4";
        this.toolStripSeparator4.Size = new System.Drawing.Size(6, 25);
        //
        // toolStripButton5
        //
        this.toolStripButton5.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
        this.toolStripButton5.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton5.Image")));
        this.toolStripButton5.ImageTransparentColor = System.Drawing.Color.Magenta;
        this.toolStripButton5.Name = "toolStripButton5";
        this.toolStripButton5.Size = new System.Drawing.Size(57, 22);
        this.toolStripButton5.Text = "清空列表";
        this.toolStripButton5.Click += new System.EventHandler(this.toolStripButton5_Click);
        //
        // toolStripSeparator5
        //
        this.toolStripSeparator5.Name = "toolStripSeparator5";
        this.toolStripSeparator5.Size = new System.Drawing.Size(6, 25);
        //
        // toolStripButton2
        //
        this.toolStripButton2.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
        this.toolStripButton2.Font = new System.Drawing.Font("宋体", 9F);
        this.toolStripButton2.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton2.Image")));
        this.toolStripButton2.ImageTransparentColor = System.Drawing.Color.Magenta;
        this.toolStripButton2.Name = "toolStripButton2";
        this.toolStripButton2.Size = new System.Drawing.Size(33, 22);
        this.toolStripButton2.Text = "关闭";
        this.toolStripButton2.Click += new System.EventHandler(this.toolStripButton2_Click);
        //
        // statusStrip1
        //
        this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
        this.tsslFileNum,
        this.toolStripStatusLabel1,
        this.tsslPlan});
        this.statusStrip1.Location = new System.Drawing.Point(0, 321);
        this.statusStrip1.Name = "statusStrip1";
        this.statusStrip1.Size = new System.Drawing.Size(536, 22);
        this.statusStrip1.TabIndex = 1;
        this.statusStrip1.Text = "statusStrip1";
        //
        // tsslFileNum
        //
        this.tsslFileNum.Name = "tsslFileNum";
        this.tsslFileNum.Size = new System.Drawing.Size(0, 17);
        //
        // toolStripStatusLabel1
        //
        this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
        this.toolStripStatusLabel1.Size = new System.Drawing.Size(23, 17);
        this.toolStripStatusLabel1.Text = "   ";
        //
        // tsslPlan
        //
        this.tsslPlan.Name = "tsslPlan";
        this.tsslPlan.Size = new System.Drawing.Size(0, 17);
        //
        // listView1
        //
        this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
        this.columnHeader6,
        this.columnHeader1,
        this.columnHeader2,
        this.columnHeader3,
        this.columnHeader4,
        this.columnHeader5,
        this.columnHeader7});
        this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
        this.listView1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
        this.listView1.FullRowSelect = true;
        this.listView1.GridLines = true;
        this.listView1.Location = new System.Drawing.Point(0, 25);
        this.listView1.Name = "listView1";
        this.listView1.Size = new System.Drawing.Size(536, 296);
        this.listView1.SmallImageList = this.imageList1;
        this.listView1.TabIndex = 2;
        this.listView1.UseCompatibleStateImageBehavior = false;
        this.listView1.View = System.Windows.Forms.View.Details;
        //
        // columnHeader6
        //
        this.columnHeader6.Text = "";
        this.columnHeader6.Width = 20;
        //
        // columnHeader1
        //
        this.columnHeader1.Text = "文件名";
        this.columnHeader1.Width = 120;
        //
        // columnHeader2
        //
        this.columnHeader2.Text = "扩展名";
        //
        // columnHeader3
        //
        this.columnHeader3.Text = "日期";
        this.columnHeader3.Width = 80;
        //
        // columnHeader4
        //
        this.columnHeader4.Text = "路径";
        this.columnHeader4.Width = 120;
        //
        // columnHeader5
        //
        this.columnHeader5.Text = "大小";
        this.columnHeader5.Width = 70;
        //
        // columnHeader7
        //
        this.columnHeader7.Text = "状态";
        //
        // imageList1
        //
        this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
        this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
        this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
        //
        // openFileDialog1
        //
        this.openFileDialog1.Filter = "所有图片|*.jpg;*.jpeg;*.gif;*.bmp;*.png";
        this.openFileDialog1.Multiselect = true;
        //
        // Form2
        //
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(536, 343);
        this.Controls.Add(this.listView1);
        this.Controls.Add(this.statusStrip1);
        this.Controls.Add(this.toolStrip1);
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
        this.MaximizeBox = false;
        this.Name = "Form2";
        this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
        this.Text = "批量图片格式转换";
        this.Load += new System.EventHandler(this.Form2_Load);
        this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form2_FormClosed);
        this.toolStrip1.ResumeLayout(false);
        this.toolStrip1.PerformLayout();
        this.statusStrip1.ResumeLayout(false);
        this.statusStrip1.PerformLayout();
        this.ResumeLayout(false);
        this.PerformLayout();

    }

    #endregion

    private System.Windows.Forms.ToolStrip toolStrip1;
    private System.Windows.Forms.StatusStrip statusStrip1;
    private System.Windows.Forms.ListView listView1;
    private System.Windows.Forms.ToolStripLabel toolStripLabel1;
    private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
    private System.Windows.Forms.ToolStripLabel toolStripLabel3;
    private System.Windows.Forms.ToolStripComboBox tscbType;
    private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
    private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
    private System.Windows.Forms.ToolStripButton toolStripButton1;
    private System.Windows.Forms.ToolStripButton toolStripButton2;
    private System.Windows.Forms.ColumnHeader columnHeader1;
    private System.Windows.Forms.ColumnHeader columnHeader2;
    private System.Windows.Forms.ColumnHeader columnHeader3;
    private System.Windows.Forms.ColumnHeader columnHeader4;
    private System.Windows.Forms.ColumnHeader columnHeader5;
    private System.Windows.Forms.OpenFileDialog openFileDialog1;
    private System.Windows.Forms.ToolStripButton toolStripButton3;
    private System.Windows.Forms.ToolStripButton toolStripButton4;
    private System.Windows.Forms.ColumnHeader columnHeader6;
    private System.Windows.Forms.ImageList imageList1;
    private System.Windows.Forms.ToolStripStatusLabel tsslFileNum;
    private System.Windows.Forms.ToolStripButton toolStripButton5;
    private System.Windows.Forms.ToolStripSeparator toolStripSeparator4;
    private System.Windows.Forms.ToolStripSeparator toolStripSeparator5;
    private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
    private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
    private System.Windows.Forms.ToolStripStatusLabel tsslPlan;
    private System.Windows.Forms.ColumnHeader columnHeader7;
}

以上就是利用C#实现批量图片格式转换功能的详细内容,更多关于C#图片格式转换的资料请关注我们其它相关文章!

(0)

相关推荐

  • C#简易图片格式转换器实现方法

    本文实例讲述了C#简易图片格式转换器实现方法.分享给大家供大家参考,具体如下: 在窗体上放一个picturebox,menustrip.在菜单上键入两个按钮,分别为"文件","格式".在"文件"下创建一个子菜单"打开",name为menuOpen,在"格式"下创建一个子菜单"转换格式",name为menuConvert. using System; using System.Collec

  • C# 图片格式转换的实例代码

    在日常工作中,经常需要不同格式的图片,有时还需要进行图片格式的相互转换,本文以一个简单的小例子,简述图片格式转换的常见方法,仅供学习分享使用,如有不足之处,还请指正. 涉及知识点 OpenFileDialog 打开文件对话框,用于选择文件,可以设置过滤后缀. FolderBrowserDialog 文件夹选择对话框,用于选择一个文件夹,可以新增. ImageFormat 图片类型枚举. Bitmap 位图对象,包含对应的属性和内容. Stream 流对象的基类. FlowLayoutPanel

  • 利用C#实现批量图片格式转换功能

    目录 实践过程 效果 代码 实践过程 效果 代码 public partial class Form1 : Form { public Form1() { InitializeComponent(); } string[] path1 = null; //用于存储选择的文件列表 string path2 = ""; //用于存储保存的路径 Bitmap bt; //声明一个转换图片格式的Bitmap对象 Thread td; //声明一个线程 int Imgtype1; //声明一个变

  • java实现截取PDF指定页并进行图片格式转换功能

    1.引入依赖 <dependency> <groupId>org.apache.pdfbox</groupId> <artifactId>pdfbox</artifactId> <version>2.0.16</version> </dependency> <dependency> <groupId>org.apache.pdfbox</groupId> <artifa

  • python实现批量图片格式转换

    本文实例为大家分享了python实现批量格式转换的具体代码,供大家参考,具体内容如下 深度学习过程中总是绕不开数据集的制作,有时候实际图片格式或大小可能与需要关心的图片信息不一致,那么我们只能手动做好数据预处理,再进行training dataset.现在将介绍最简单的格式转换问题.可以支持批量图片任意格式转换. 直接上代码: # 将jpg格式转位png import os from PIL import Image import shutil import sys # Define the i

  • python利用tkinter实现图片格式转换的示例

    代码 import os from PIL import Image import tkinter import tkinter.filedialog import tkinter.messagebox class Window(): def __init__(self): self.root = root = tkinter.Tk() self.menu = tkinter.Menu(root) self.submenu = tkinter.Menu(self.menu, tearoff=0)

  • Python实现图片格式转换小程序

    基于Python实现图片格式转换的小程序,供大家参考,具体内容如下 特点: 1.批量处理图片2.转换常见的4种图片格式 运行窗口 运行窗口-1 选择图片(可批量选择)-2 假设选中4张JEPG格式的图片 格式选择窗口-3 假设选择目标格式PNG 结束窗口-4 结果展示-5 可以发现4个JEPG目标图片成功转换为PNG格式的图片 代码 import tkinter as tk import tkinter.messagebox from tkinter import filedialog from

  • java图片格式转换的三段代码

    网上关于java图片格式内容的文章不是很多,也不是很完整,小编搜集了三段java图片格式转换代码,分享给大家: 第一段:java图片格式转换代码 import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.Scanner; import javax.imageio.*; public class FormatConversion { public st

  • PHP简单实现图片格式转换(jpg转png,gif转png等)

    需求 开发过程中总会遇到一些需求需要对图片格式进行转换.比如 gif转png,jpg转png 如最近使用某平台的图片文件识别,居然不支持gif格式,那么就需要将gif处理成png等. 依赖 php扩展 gd 和 exif 实现 /** * 图片格式转换 * @param string $image_path 文件路径或url * @param string $to_ext 待转格式,支持png,gif,jpeg,wbmp,webp,xbm * @param null|string $save_p

  • Winform中实现图片格式转换

    场景 选择一张照片并选择保存位置和要转换的图片格式实现图片格式转换. 项目运行效果 实现 新建一个窗体页面,然后设计页面布局如下 选择图片按钮点击事件中 private void toolStripButton3_Click(object sender, EventArgs e)//选择转换文件的按钮 { if (openFileDialog1.ShowDialog() == DialogResult.OK) //判断是否选择文件 { listView1.Items.Clear(); //清空l

  • python图片格式转换脚本

    目录 前言 1.cv2 1.1 导包 1.2 路径设置 1.3 改格式重新传 1.4 查看结果 2.pillow 2.1 导包 2.2 路径设置 2.3 写格式修改函数 2.4 开始转换 2.5 查看结果 前言 常见的图像任务通常需要把照片统一成相同的格式,所以此文章正是为了统一格式而生,常见的主要有cv2和PIL.Image的相关操作,照片格式是一串数字加上后缀名 1.cv2 pip install opencv-python之后就可以import cv2 1.1 导包 import os i

随机推荐