c#的面向AI编程-批量转PNG文件为JPG过滤掉小图标--【InsCodeAI编程】

InsCodeAI的面向AI编程系列文章目录

InsCodeAI编程专集框架技术及难度系数(五星制)
java的面向AI编程-InsCode-批量转PNG文件为JPG过滤掉小图标难度★✫✰✰✰
java的面向AI编程-读一个代码文件换里面的代码行–【InsCodeAI编程】
c#的面向AI编程-批量改文件名的救赎–【InsCodeAI编程】
c#的面向AI编程-批量处理JPG图片为固定宽度

本系列校训

互相伤害互相卷,玩命学习要你管,天生我才必有用,我命由我不由天!
有了AI牛翻天,作业难度全一般,发财小手动一动,关注收藏点一点。

毕设(作业)的技术铺垫

语言选择收录专辑链接卷的程度
C张雪峰推荐选择了计算机专业之后-在大学期间卷起来-【大学生活篇】★★★✫✰
JAVA黑马B站视频JAVA部分的知识范围、学习步骤详解★★★★★
JAVAWEB黑马B站视频JAVAWEB部分的知识范围、学习步骤详解★★★★★
SpringBootSpringBoot知识范围-学习步骤【JSB系列之000】★★★★★
微信小程序详细解析黑马微信小程序视频–【思维导图知识范围】★★★✰✰
python详细解析python视频选择–【思维导图知识范围】★★✫✰✰
phpPHP要怎么学–【思维导图知识范围】★★★✫✰

环境及工具:

本系列环境

环境win11
工具idea 2017/idea 2018 /visual studio 2017
jdk
数据库
maven
项目导入方式打开目录
数据库前端工具
使用AIInsCode

作业说明

之前用AI弄了个JAVA批量改PNG为JPG的,程序也运行的没有问题,但是JAVA代码的代码的好,C#可以做EXE呀。
所以,我想再用AI试一下,用C#做实用的小工具。这样,就方便了。
现在不是研究AI给初学者带来了多大的冲击,而是怎么用AI更好的完成自己的工作。
甚至现在看到了这样的文章
《AI在招聘领域有哪些应用场景?》
《精通“微表情&面相学“AI面试官已就位 请接招》
HR都开始玩AI了,那你做为程序员或准程序员,你还不会AI你怎么破局呢?
会不会发展到面试官只管问问题,天南海北的问就行了,屋子里安有摄像头,然后,面试完直接问AI,这个应试者技术打多少分,素质打多少分?反应能力打多少分,抗压能力打多少分?
AI可以一票否决应试者。会不会在不远的将来就真的实现?

总体功能

好了,我来说一下这个作业的功能。
就是把一些项目目录下的PNG图片转成JPG图片(不包括那些小图标的PNG假定为宽小于100,或高小于100)

向AI发招

在这里插入图片描述
AI 再一次的给出了linux 命令行。
给它转转向。
在这里插入图片描述

全部代码如下:


using System;
using System.IO;

namespace FindPNGImages
{
    class Program
    {
        static void Main(string[] args)
        {
            string directoryPath = "C:\\path\\to\\directory";

            FindPNGImages(directoryPath);

            Console.ReadKey();
        }

        static void FindPNGImages(string directoryPath)
        {
            DirectoryInfo directory = new DirectoryInfo(directoryPath);

            foreach (FileInfo file in directory.GetFiles("*.png"))
            {
                Console.WriteLine(file.FullName);
            }

            foreach (DirectoryInfo subDirectory in directory.GetDirectories())
            {
                FindPNGImages(subDirectory.FullName);
            }
        }
    }
}

验证一下:
很完美的就跑起来了。
在这里插入图片描述

在这里插入图片描述
我放项目里的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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

        static void FindPNGImages(string directoryPath)
        {
            DirectoryInfo directory = new DirectoryInfo(directoryPath);

            foreach (FileInfo file in directory.GetFiles("*.png"))
            {
                Console.WriteLine(file.FullName);
            }

            foreach (DirectoryInfo subDirectory in directory.GetDirectories())
            {
                FindPNGImages(subDirectory.FullName);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string directoryPath = "G:\\vue";

            FindPNGImages(directoryPath);

            Console.ReadKey();


        }
    }
}

不过,出现了一个异常,
在这里插入图片描述
由于 这个异常出现的N多的图片的中间,所以,我们先做一个判断,跳过去,让程序顺畅跑下来。

好了,找到了几百张图片,
后面的这个问题没懂。我也不太会c# 先跳过去。
在这里插入图片描述
在这里插入图片描述

using System;
using System.Drawing;
using System.IO;

namespace FindPNGImages
{
    class Program
    {
        static void Main(string[] args)
        {
            string directoryPath = "C:\\path\\to\\directory";

            FindPNGImages(directoryPath);

            Console.ReadKey();
        }

        static void FindPNGImages(string directoryPath)
        {
            DirectoryInfo directory = new DirectoryInfo(directoryPath);

            foreach (FileInfo file in directory.GetFiles("*.png"))
            {
                Image image = Image.FromFile(file.FullName);
                if (image.Height > 100 && image.Width > 120)
                {
                    Console.WriteLine(file.FullName);
                }
                image.Dispose();
            }

            foreach (DirectoryInfo subDirectory in directory.GetDirectories())
            {
                FindPNGImages(subDirectory.FullName);
            }
        }
    }
}

那么,我们需要的是转成JPG,然后,删掉PNG
先一个个的向AI问

在这里插入图片描述
这一次AI“思考”的时间比较长。

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

namespace FindAndSavePNGImages
{
    class Program
    {
        static void Main(string[] args)
        {
            string directoryPath = "C:\\path\\to\\directory";

            FindAndSavePNGImages(directoryPath);

            Console.ReadKey();
        }

        static void FindAndSavePNGImages(string directoryPath)
        {
            DirectoryInfo directory = new DirectoryInfo(directoryPath);

            foreach (FileInfo file in directory.GetFiles("*.png"))
            {
                using (Image image = Image.FromFile(file.FullName))
                {
                    if (image.Height > 100 && image.Width > 120)
                    {
                        string jpegPath = Path.ChangeExtension(file.FullName, ".jpg");
                        using (Bitmap bitmap = new Bitmap(image.Width, image.Height))
                        {
                            using (Graphics graphics = Graphics.FromImage(bitmap))
                            {
                                graphics.DrawImage(image, Point.Empty);
                            }
                            bitmap.Save(jpegPath, ImageFormat.Jpeg);
                        }
                        Console.WriteLine($"Image {file.FullName} converted to {jpegPath}");
                    }
                }
            }

            foreach (DirectoryInfo subDirectory in directory.GetDirectories())
            {
                FindAndSavePNGImages(subDirectory.FullName);
            }
        }
    }
}

 

不知道啥情况的运行一下:
在这里插入图片描述

在这里插入图片描述

经过了漫长的几分钟之后。。
程序好象是成功的完成了??
在这里插入图片描述
看来这是成了。
长宽大的都转了,小的就没有转。
只是有一些PNG转成了黑色,有一些转成了白色。这个就先不管了。毕竟,实际的大图,都是满屏的。
在这里插入图片描述
那么,我们就可以把转的PNG删了。
在这里插入图片描述

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

namespace FindAndSavePNGImages
{
    class Program
    {
        static void Main(string[] args)
        {
            string directoryPath = "C:\\path\\to\\directory";

            FindAndSavePNGImages(directoryPath);

            Console.ReadKey();
        }

        static void FindAndSavePNGImages(string directoryPath)
        {
            DirectoryInfo directory = new DirectoryInfo(directoryPath);

            foreach (FileInfo file in directory.GetFiles("*.png"))
            {
                using (Image image = Image.FromFile(file.FullName))
                {
                    if (image.Height > 100 && image.Width > 120)
                    {
                        string jpegPath = Path.ChangeExtension(file.FullName, ".jpg");
                        using (Bitmap bitmap = new Bitmap(image.Width, image.Height))
                        {
                            using (Graphics graphics = Graphics.FromImage(bitmap))
                            {
                                graphics.DrawImage(image, Point.Empty);
                            }
                            bitmap.Save(jpegPath, ImageFormat.Jpeg);
                        }
                        File.Delete(file.FullName);
                        Console.WriteLine($"Image {file.FullName} converted to {jpegPath} and deleted");
                    }
                }
            }

            foreach (DirectoryInfo subDirectory in directory.GetDirectories())
            {
                FindAndSavePNGImages(subDirectory.FullName);
            }
        }
    }
}

这也说明了AI强大,它确实就加了一行。
在这里插入图片描述
因为我对C# 也不熟,所以,我只好把这个错误交给AI。
在这里插入图片描述

using (Image image = Image.FromFile(file.FullName))
{
    if (image.Height > 100 && image.Width > 120)
    {
        string jpegPath = Path.ChangeExtension(file.FullName, ".jpg");
        using (Bitmap bitmap = new Bitmap(image.Width, image.Height))
        {
            using (Graphics graphics = Graphics.FromImage(bitmap))
            {
                graphics.DrawImage(image, Point.Empty);
            }
            bitmap.Save(jpegPath, ImageFormat.Jpeg);
        }
        image.Dispose(); // 释放图片资源
        File.Delete(file.FullName);
        Console.WriteLine($"Image {file.FullName} converted to {jpegPath} and deleted");
    }
}

在这里插入图片描述

再打开,刚才的那个目录
在这里插入图片描述

就这么帅气。

这个事成了
如果这个代码再配合其它的代码,那就妥妥的一个好用的小工具了。
这个就是项目里的日常算法,当然,放在你的作业里,绝绝对对的是核心代码了!

什么是核心代码:

应用软件的核心代码是指这个程序最关键部分的代码。例如WinRAR,它的核心代码就是压缩算法部分,而诸如用户界面、操作系统移植等部分就无足轻重了。
商城类的核心代码是指业务层的代码,比如你商城的核心代码就是:商品、购物车、创建订单、支付这些代码就是核心代码。

作为程序员,我们经常需要看懂别人的代码。特别是在开源社区中,我们需要理解许多优秀的开源项目的代码。而在Gitee这样的代码托管平台上,我们如何快速有效地看懂别人的代码呢?本文将为大家介绍一些方法。

1.阅读README和项目介绍

在Gitee上,许多开源项目都会有自己的README文件或项目介绍。这些文件一般会介绍项目的背景、功能、使用方法等内容,可以帮助我们快速了解这个开源项目的基本情况。如果我们能够从这些文件中找到与自己相关的内容,就可以快速入手这个开源项目的代码。

2.了解项目结构和代码组织

在阅读代码之前,我们需要先了解这个开源项目的代码结构和代码组织方式。通常,开源项目会将不同的功能模块封装到不同的代码文件中,并按照一定的目录结构组织起来。如果我们能够了解这个开源项目的代码组织方式,就能更加快速地找到所需的代码。

3.利用IDE和工具

IDE和一些代码阅读工具可以帮助我们更快速、更高效地阅读代码。例如,Java开发者可以使用Eclipse或IntelliJ IDEA这样的IDE,可以快速打开代码文件、查看类、方法和变量等信息。另外,一些代码阅读工具,如Source Insight、CodeCompare等,可以帮助我们更方便地查看代码的结构和关系,以及快速跳转到相关代码。

4.关注代码注释和文档

良好的代码注释和文档可以帮助我们更快速地理解代码。因此,在阅读别人的代码时,我们可以将注意力放在代码注释和文档上。有些开源项目会提供详细的文档,有些则注重代码注释。如果我们能够针对代码注释和文档有一个系统的阅读和理解,就能更快速地掌握别人的代码。

5.跑通测试和运行项目

如果我们想更深入地了解别人的代码,可以试着跑通相关的测试,或者直接运行这个开源项目。通过跑测试和运行项目,我们可以更加直观地了解代码的实现细节和具体的业务逻辑。

总结:

以上就是在Gitee上快速理解他人代码的一些方法,希望对大家有所帮助。当然,阅读代码是一件需要耐心和细心的事情,需要我们多花一点时间和心思。只有沉下心来,慢慢阅读每一行代码,才能真正理解它们的含义和作用。

总结

就一句,AI太强了,真的太强了。
以前的学习的人,没有那么正规,但是潜下心写代码。现在的人呢?除了各种网络的BBLL,真心写代码的还能找不到工作?就算你不会写,但是你看了那么多的视频,用AI这么好玩的事情,还不赶紧试一试?

论文参考
基于jsp的塞北村镇旅游网站的设计与实现–【毕业论文】
https://blog.csdn.net/dearmite/article/details/131962993

配套资源

c#的面向AI编程-批量转PNG文件为JPG过滤掉小图标–【InsCodeAI编程】
https://download.csdn.net/download/dearmite/88250564

编译好的小工具:
加了一个以数字为索引重命名文件夹内所有文件的功能(不支持子文件夹)
加入PNG转JPG 第三版

https://download.csdn.net/download/dearmite/88250580

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

项目花园范德彪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值