欢迎光临散文网 会员登陆 & 注册

[C#]当屏幕检测到白色启动原神,黑色启动星穹铁道的抽象项目

2023-08-16 23:37 作者:疯狂的战斗鸡plus  | 我要投稿


首先:这玩意儿就是纯纯的整活,一个小时就完成了,大家就当看个乐呵


灵感来自于基于【白屏检测】的 原神启动器

以及其评论

就是这位老哥

于是就用C#做了这么一个玩意儿

界面先随便看着吧

使用方法也是十分的简单,只要输入原神和星铁的exe地址之后当检测到全屏的白色或者黑色就会启动对应的游戏十分简单粗暴

接下来是代码:


public Form1()

        {

            InitializeComponent();

        }

        bool isshowW =false;

        bool isshowB = false;

        private void Timer_Tick(object sender, EventArgs e)

        {

            Rectangle rectangle = Screen.PrimaryScreen.Bounds;

            Bitmap bitmap = new Bitmap(rectangle.Width, rectangle.Height, PixelFormat.Format32bppArgb);

            Graphics g = Graphics.FromImage(bitmap);

            g.CopyFromScreen(rectangle.Left, rectangle.Top, 0, 0, bitmap.Size);


            int totalPixels = bitmap.Width * bitmap.Height;

            int rSum = 0, gSum = 0, bSum = 0;


            BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            IntPtr ptr = bitmapData.Scan0;


            int bytes = Math.Abs(bitmapData.Stride) * bitmap.Height;

            byte[] rgbValues = new byte[bytes];


            Marshal.Copy(ptr, rgbValues, 0, bytes);


            for (int i = 0; i < bytes; i += 4)

            {

                byte b = rgbValues[i];

                byte gs = rgbValues[i + 1];

                byte r = rgbValues[i + 2];


                rSum += r;

                gSum += gs;

                bSum += b;

            }


            bitmap.UnlockBits(bitmapData);

            bitmap.Dispose();

            g.Dispose();


            int avgR = rSum / totalPixels;

            int avgG = gSum / totalPixels;

            int avgB = bSum / totalPixels;


            bool isScreenWhite = IsColorCloseToWhite(avgR, avgG, avgB);

            bool isScreenBlack = IsColorCloseToBlack(avgR, avgG, avgB);


            if (isScreenWhite)

            {

                // 屏幕全白,执行相应操作

                if(isshowW == false)

                {

                    Process.Start(textBox1.Text);

                    isshowW = true;

                }

            }

            else if (!isScreenWhite)

            {

                isshowW = false;

            }

            if (isScreenBlack)

            {

                if (isshowB == false)

                {

                    Process.Start(textBox2.Text);

                    isshowB = true;

                }

            }

            else if (!isScreenBlack)

            {

                isshowB = false;

            }

        }


        private bool IsColorCloseToWhite(int r, int g, int b)

        {

            // 定义一个阈值,判断颜色是否接近白色

            int threshold = 250;

            return r >= threshold && g >= threshold && b >= threshold;

        }

        private bool IsColorCloseToBlack(int r, int g, int b)

        {

            // 定义一个阈值,判断颜色是否接近白色

            int threshold = 15;

            return r <= threshold && g <= threshold && b <= threshold;

        }

        bool isqidong =false;

        private void button1_Click(object sender, EventArgs e)

        {

            Timer timer = new Timer();

            timer.Tick += Timer_Tick;

            if (!isqidong)

            {

                timer.Start();

                button1.Text = "停止";

                isqidong = true;

            }

            else

            {

                timer.Stop();

                button1.Text = "启动";

                isqidong = false;

            }

            

        }

    }

(放心绝对绿色无污染)
下载地址:

链接:https://pan.baidu.com/s/1ghSbFrOEZ0-_RlVf1uxegQ?pwd=f9rk 

提取码:f9rk

顺便预告一下下一个视频

炒冷饭


[C#]当屏幕检测到白色启动原神,黑色启动星穹铁道的抽象项目的评论 (共 条)

分享到微博请遵守国家法律