gpt4 book ai didi

c++ - 有没有一种方法可以在随机位置上反转颜色?

转载 作者:行者123 更新时间:2023-11-30 04:41:42 25 4
gpt4 key购买 nike

我想在屏幕上拍摄颜色并将其反转,然后使用BitBlt函数将它们打印回屏幕,因为我知道该功能可以拍摄照片,复制并粘贴
它回到屏幕。

基本上,我想要的是使用DSTINVERT反转颜色,它执行的操作是在屏幕上获取颜色,将它们反转并打印回到屏幕上。

因此,我使用了它,并且想要在屏幕上进行随机定位,我使用GetSystemMetrics函数获取了屏幕像素,并在屏幕上进行了随机打印。
但这对我不起作用,什么也不打印,什么也不做,如果我输入随机分辨率(1920x1080),它可以工作并随机打印,但是我希望该程序在所有屏幕上也能正常工作。

希望能有所帮助。

#include <iostream>
#include <Windows.h>
#include <time.h>

using namespace std;

int main()
{
srand(time(0));
HDC desktop = GetDC(GetDesktopWindow());

int width = GetSystemMetrics(SM_CXSCREEN);
int height = GetSystemMetrics(SM_CYSCREEN);

for (int i = 0; i < 1000; i++) {

// Position on the screen
int x = rand() % width;
int y = rand() % height;

Sleep(3000);
BitBlt(desktop, width, height, 250, 250, desktop, width, height, DSTINVERT);
}
return 0;
}

而且,如果有人解释这两个参数(7、8),我也很喜欢,因为我对这样做的了解不多,所以我做了相同的随机性。

最佳答案

抱歉!我的错。

我已经使用了宽度和高度作为参数。
我需要使用x和y。

我的程序现在运行良好。

但我仍然想请您解释一下参数(8、7)。谢谢!

#include <iostream>
#include <Windows.h>
#include <time.h>

using namespace std;

int main()
{
srand(time(0));
HDC desktop = GetDC(GetDesktopWindow());

int width = GetSystemMetrics(SM_CXSCREEN);
int height = GetSystemMetrics(SM_CYSCREEN);

for (int i = 0; i < 1000; i++) {

// Size
int size1 = rand() % 500;
int size2 = rand() % 500;

// Position on the screen
int x = rand() % width;
int y = rand() % height;

Sleep(3000);
BitBlt(desktop, x, y, size1, size2, desktop, x, y, DSTINVERT);
}
return 0;
}

关于c++ - 有没有一种方法可以在随机位置上反转颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59073013/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com