2

在 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;
}

但屏幕似乎为NULL

抱歉新手问题

但是有人可以让我知道如何访问帧缓冲区来读取像素吗?

欢迎任何可能的方式

4

1 回答 1

5

SDL 不允许您读取桌面的像素。它抽象出这些功能,因为它们是不可移植的(例如,在控制台或嵌入式设备上读取桌面像素意味着什么?)因此,您将需要直接使用 Windows API。自从我使用 Windows 以来已经有一段时间了,但至少在几年前,这个过程是这样的:

  1. 获取桌面设备上下文。

  2. 从中读取像素。

For example, the code might look something like this (again roughly speaking, I don't use windows any more so I am not 100% here):

 HDC desktopDC = CreateDCAsNull("DISPLAY", NULL, NULL, NULL);
 int pixel=GetPixel(desktopDC, x, y);
于 2011-06-26T10:03:15.680 回答