kim*_*yun 2 c desktop framebuffer pixel
在Windows XP中,C编程语言
我想快速读取屏幕的一个像素(即你现在可以看到的1024*768)
我认为帧缓冲是解决方案.
所以
我试过了
#include "SDL.h"
#include <stdio.h>
#include <time.h>
SDL_Surface *screen;
int main(int argc, char *argv[])
{
if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
{
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}
screen = SDL_GetVideoSurface();
if ( screen == NULL )
{
exit(1);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但屏幕似乎是NULL
对不起新问题
但有人可以告诉我如何访问framebuffer来读取像素吗?
欢迎任何可能的方式
SDL不允许您读取桌面的像素.它抽象出这些功能,因为它们是不可移植的(例如,在控制台或嵌入式设备上读取桌面像素意味着什么?)因此,您需要直接使用Windows API.自从我使用Windows以来已经有一段时间了,但至少在几年前,这个过程的工作原理如下:
获取桌面设备上下文.
从中读取像素.
例如,代码可能看起来像这样(再次粗略地说,我不再使用Windows,所以我不是100%在这里):
HDC desktopDC = CreateDCAsNull("DISPLAY", NULL, NULL, NULL);
int pixel=GetPixel(desktopDC, x, y);
Run Code Online (Sandbox Code Playgroud)