惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
G
Google Developers Blog
J
Java Code Geeks
爱范儿
爱范儿
Microsoft Azure Blog
Microsoft Azure Blog
美团技术团队
人人都是产品经理
人人都是产品经理
Martin Fowler
Martin Fowler
IT之家
IT之家
博客园_首页
B
Blog RSS Feed
Google DeepMind News
Google DeepMind News
B
Blog
U
Unit 42
Apple Machine Learning Research
Apple Machine Learning Research
L
LangChain Blog
Stack Overflow Blog
Stack Overflow Blog
罗磊的独立博客
N
Netflix TechBlog - Medium
T
Tailwind CSS Blog
博客园 - 聂微东
腾讯CDC
A
About on SuperTechFans

博客园 - iDEAAM

logstash 如何从oracle 导入 pgsql IIS如何部署python django项目 IIS 如何部署net8 和 如何配置反向代理 ARR、URL Rewrite python 备份文件,从 D盘 到Z盘。并且保留15天的文件 git 如何排除 bin obj nginx 配置 自签名https证书 powershell 计划任务 定时任务 如何调用get接口 使用nssm在windows服务器上部署nodejs 退出远程桌面不锁屏 PDF 转 Excel 非常完美的java包 sublime 选择有规律的数据,同时快速编辑多行内容 去除重复行或者只保留唯一值 C#中 同步方法调用异步方法不死锁的方法 async await task windows 2008 r2 iis https 配置方法 vue js中,利用json数据临时生成一个可下载csv的功能 git常用命令 C#下载远程文件并打包 从 ASP.NET MVC 和 Web API 升级到 ASP.NET Core MVC C# asp.net开源插件推荐:PdfiumViewer ( pdf 转成 图片png pdf convert to image ) 在asp.net mvc中使用了owin startup如何使用 swagger插件
c# 把现有图片顶部top50px 处理成白色
iDEAAM · 2023-04-12 · via 博客园 - iDEAAM
 /// <summary>
        /// 把现有图片顶部50px刷成白色,去水印
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBrushWhite_Click(object sender, EventArgs e)
        {

            // Create a new instance of the BackgroundWorker class
            BackgroundWorker worker = new BackgroundWorker();

            // Set the DoWork event handler
            worker.DoWork += new DoWorkEventHandler(btnBrushWhite_ClickCore);

            // Start the background worker
            worker.RunWorkerAsync();

            this.btnBrushWhite.Enabled = false;
        }


        private async void btnBrushWhite_ClickCore(object sender, DoWorkEventArgs e)
        {
            var appSettings = ConfigurationManager.AppSettings; // Get the appSettings object

            var imgDicPath = appSettings["ImgDicPath"];
            var imgDicOutPath = appSettings["ImgDicOutPath"];
            // Get an array of file paths in the directory
            string[] filePaths = Directory.GetFiles(imgDicPath);
            if (!Directory.Exists(imgDicOutPath))
            {
                Directory.CreateDirectory(imgDicOutPath);
            }

            this.pbHandleImg.Maximum = filePaths.Length;

            var count = 0;
            var startTime = DateTime.Parse("2022-08-02");

            for (int i = 0; i < filePaths.Length; i++)
            {
                await Task.Delay(10);

                this.pbHandleImg.Value = i + 1;
                var filePath = filePaths[i];

                // 获取图片文件大小
                FileInfo fileInfo = new FileInfo(filePath);
                long fileSizeInBytes = fileInfo.Length;
                //获取上次修改时间
                var lastModified = fileInfo.LastWriteTime;
                if (lastModified < startTime || fileSizeInBytes == 0)
                {
                    this.lblTips.Text = filePath + " 无需处理";
                    continue;
                }
                this.lblTips.Text = filePath;
                try
                {
                    using (Image imageCopy = Image.FromFile(filePath))
                    {
                        // Create a graphics object from the image
                        using (Graphics graphics = Graphics.FromImage(imageCopy))
                        {
                            // Create a white brush
                            using (SolidBrush whiteBrush = new SolidBrush(Color.White))
                            {
                                // Fill a rectangle at the top of the image with the white brush
                                graphics.FillRectangle(whiteBrush, 0, 0, imageCopy.Width, 50);

                                // Save the modified image to file
                                imageCopy.Save(filePath.Replace(imgDicPath, imgDicOutPath));
                            }
                        }
                        
                    }
                    count++;
                }
                catch (System.Exception ex)
                {

                    // Specify the file path and name
                    string path =  AppDomain.CurrentDomain.BaseDirectory+"/log.txt";

                    // Open the file in append mode and create it if it doesn't exist
                    using (StreamWriter writer = new StreamWriter(path, true))
                    {
                        // Write the log message to the file
                        writer.WriteLine(DateTime.Now+","+filePath+","+ex.Message);
                    }
                    continue;
                }

            }
            this.btnBrushWhite.Enabled = true;
            MessageBox.Show(string.Format("执行完毕,共处理{0}张图片", count));
        }