• 大小: 0.45M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-04-24
  • 语言: C#
  • 标签: 文件夹  批量  文件  

资源简介

可以批量转换JPG的尺寸和压缩的质量

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.IO;
 
namespace JpgBatchConvert
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender EventArgs e)
        {
            maxValue.KeyPress += tbox_KeyPress_Number;
        }

        private async void button1_Click(object sender EventArgs e)
        {
            if (dirPath.Text == ““)
            {
                MessageBox.Show(“请输入文件夹地址“);
                return;
            }
            if (!Directory.Exists(dirPath.Text))
            {
                MessageBox.Show(“文件夹地址不存在“);
                return;
            }
            if (maxValue.Text == ““)
            {
                MessageBox.Show(“高宽“);
                return;
            }

            button1.Enabled = false;
            button1.Text = “转换中...“;

            await StartConvert();
            textBox1.Text = Global.ErrorFIle;
            Global.ErrorFIle = ““;

            MessageBox.Show(“全部转换成功“);
            button1.Enabled = true;
            button1.Text = “开始转换“;
        }

        private Task StartConvert()
        {
            int maxSize = int.Parse(maxValue.Text);
            int jpgQuality = Convert.ToInt16(quality.Value);
            Process process = new Process();
            IProgress progress = new Progress((progressValue) => { label5.Text =“转换完成:“ + progressValue.ToString(); });
            string LeftOrRight = “Right“;
            if(radioButton2.Checked)
                LeftOrRight = “Left“;
            return Task.Run(() => process.batchConvert(progressmaxSizejpgQualitydirPath.Text checkBox1.Checked LeftOrRight));
        }

        public static void tbox_KeyPress_Number(object sender System.Windows.Forms.KeyPressEventArgs e)
        {
            //数值输入控制:只能输入数字,点和回车
            if (!(char.IsNumber(e.KeyChar)) && e.KeyChar != (char)13 && e.KeyChar != (char)8 )
                e.Handled = true;
        }
        
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-02-27 15:29  JpgBatchConvert\
     目录           0  2020-02-27 15:29  JpgBatchConvert\.vs\
     目录           0  2020-02-27 15:29  JpgBatchConvert\.vs\JpgBatchConvert\
     目录           0  2020-02-27 15:29  JpgBatchConvert\.vs\JpgBatchConvert\v14\
     文件       49664  2016-11-16 21:28  JpgBatchConvert\.vs\JpgBatchConvert\v14\.suo
     目录           0  2020-02-27 15:29  JpgBatchConvert\.vs\JpgBatchConvert\v15\
     文件       53248  2020-01-05 16:09  JpgBatchConvert\.vs\JpgBatchConvert\v15\.suo
     目录           0  2020-02-27 15:29  JpgBatchConvert\.vs\JpgBatchConvert\v15\Server\
     目录           0  2020-02-27 15:29  JpgBatchConvert\.vs\JpgBatchConvert\v15\Server\sqlite3\
     文件           0  2019-04-20 19:10  JpgBatchConvert\.vs\JpgBatchConvert\v15\Server\sqlite3\db.lock
     文件      581632  2020-01-05 16:09  JpgBatchConvert\.vs\JpgBatchConvert\v15\Server\sqlite3\storage.ide
     目录           0  2020-02-27 15:29  JpgBatchConvert\JpgBatchConvert\
     文件         184  2018-01-23 08:35  JpgBatchConvert\JpgBatchConvert\App.config
     目录           0  2020-02-27 15:29  JpgBatchConvert\JpgBatchConvert\bin\
     目录           0  2020-02-27 15:29  JpgBatchConvert\JpgBatchConvert\bin\Debug\
     文件      207360  2020-01-05 15:59  JpgBatchConvert\JpgBatchConvert\bin\Debug\JpgBatchConvert.exe
     文件         184  2018-01-23 08:35  JpgBatchConvert\JpgBatchConvert\bin\Debug\JpgBatchConvert.exe.config
     文件       34304  2020-01-05 15:59  JpgBatchConvert\JpgBatchConvert\bin\Debug\JpgBatchConvert.pdb
     文件       24216  2018-01-23 08:58  JpgBatchConvert\JpgBatchConvert\bin\Debug\JpgBatchConvert.vshost.exe
     文件         184  2018-01-23 08:35  JpgBatchConvert\JpgBatchConvert\bin\Debug\JpgBatchConvert.vshost.exe.config
     文件         490  2013-03-18 17:00  JpgBatchConvert\JpgBatchConvert\bin\Debug\JpgBatchConvert.vshost.exe.manifest
     目录           0  2016-04-27 09:33  JpgBatchConvert\JpgBatchConvert\bin\Release\
     文件        2440  2020-01-05 15:59  JpgBatchConvert\JpgBatchConvert\Form1.cs
     文件       11010  2020-01-05 15:58  JpgBatchConvert\JpgBatchConvert\Form1.Designer.cs
     文件      147455  2020-01-05 15:58  JpgBatchConvert\JpgBatchConvert\Form1.resx
     文件         245  2019-04-20 19:14  JpgBatchConvert\JpgBatchConvert\Global.cs
     文件        3461  2020-01-05 15:56  JpgBatchConvert\JpgBatchConvert\JPG.cs
     文件        4254  2019-04-20 19:16  JpgBatchConvert\JpgBatchConvert\JpgBatchConvert.csproj
     目录           0  2020-02-27 15:29  JpgBatchConvert\JpgBatchConvert\obj\
     目录           0  2020-02-27 15:29  JpgBatchConvert\JpgBatchConvert\obj\Debug\
     文件        1452  2020-01-05 15:53  JpgBatchConvert\JpgBatchConvert\obj\Debug\DesignTimeResolveAssemblyReferences.cache
............此处省略25个文件信息

评论

共有 条评论