画图画蒙娜丽莎

Windows-Hacks.git
首先打开一个空的画图,自动画资源里面的画。

using ImageProcessing;
using System;
using System.Diagnostics;
using System.Drawing;
using WindowsAPI;

namespace WindowsHacks
{
    class Painter
    {

        private const int StartX = 15;
        private const int StartY = 150;
        private const int PixelSize = 1;
        private const int MaxWidth = 168;
        private const int MaxHeight = 67;
        private static IntPtr hWnd;

        /// <summary>
        /// Draw a bitmap manually into Microsoft Paint.
        /// </summary>
        public static void Run()
        {
            if (Window.DoesExist("Untitled - Paint"))
            {
                hWnd = Window.Get("Untitled - Paint");
            }
            else if (Window.DoesExist("无标题 - 画图"))
            {
                hWnd = Window.Get("无标题 - 画图");
            }
            else
            {
                Console.WriteLine("Microsoft Paint Window with the name \"Untitled - Paint\" not found.");
                Console.WriteLine("Microsoft Paint is Start New.");
                StartPaint();
                while (!Window.DoesExist("Untitled - Paint") && !Window.DoesExist("无标题 - 画图")) ;
                Run();
                return;
            }

            Bitmap bitmap = Properties.Resources.mona;

            Bitmap bmp = Effect.Threshold(bitmap, 150);

            Color pixel;
            bool pencilDown = false;

            Window.SetFocused(hWnd);
            //Window.Move(hWnd, 0, 0);

            System.Threading.Thread.Sleep(100);

            // The actual drawing.
            for (int y = 0; y < bmp.Height; y++)
            {
                for (int x = 0; x < bmp.Width; x++)
                {
                    pixel = bmp.GetPixel(x, y);

                    if (Window.IsFocused(hWnd) == false) return;

                    if (pixel.ToArgb() == Color.Black.ToArgb() && pencilDown == false)
                    {
                        System.Threading.Thread.Sleep(10);
                        MouseDown(x, y);
                        pencilDown = true;
                    }
                    else if (pixel.ToArgb() == Color.White.ToArgb() && pencilDown == true)
                    {
                        System.Threading.Thread.Sleep(10);
                        MouseUp(x - 1, y);
                        pencilDown = false;
                    }
                }

                if (pencilDown)
                {
                    MouseUp(bmp.Width, y);
                    pencilDown = false;
                }

            }
        }

        private static void SelectBlackPencil()
        {
            Mouse.LeftClick(Window.GetLocation(hWnd).X + 763, Window.GetLocation(hWnd).Y + 60);
        }

        private static void SelectWhitePencil()
        {
            Mouse.LeftClick(Window.GetLocation(hWnd).X + 763, Window.GetLocation(hWnd).Y + 80);
        }

        private static void MouseDown(int x, int y)
        {
            Mouse.LeftDown(Window.GetLocation(hWnd).X + StartX + (PixelSize * x), Window.GetLocation(hWnd).Y + StartY + (PixelSize * y));
        }

        private static void MouseUp(int x, int y)
        {
            Mouse.LeftUp(Window.GetLocation(hWnd).X + StartX + (PixelSize * x), Window.GetLocation(hWnd).Y + StartY + (PixelSize * y));
        }

        private static void MouseUp()
        {
            Mouse.LeftUp();
        }

        private static void StartPaint()
        {
            ProcessStartInfo processStartInfo = new ProcessStartInfo
            {
                FileName = "powershell",
                Arguments = "mspaint",
                UseShellExecute = false,
                CreateNoWindow = true
            };
            Process.Start(processStartInfo);
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Admini$trat0r

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

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

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

打赏作者

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

抵扣说明:

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

余额充值