read a pixel of the screen(i.e. 1024*768 which you can see now)
in Windows XP, C programming language
I want to read a pixel of the screen(i.e. 1024*768 which you can see now) in fast way
I think the framebuffer is the solution.
so
I tried
#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;
}
开发者_开发问答but the screen seems NULL
sorry for newb question
but could somebody let me know how to access framebuffer for reading a pixel?
any possible ways are welcome
SDL doesn't let you read the pixels of the desktop. It abstracts away those features since they are non-portable (for example, what would it mean on a console or embedded device to read a desktop pixel?) As a result, you will need to use the Windows API directly. It has been a while since I've used windows, but at least a couple of years ago the process worked something like this:
Get the desktop device context.
Read the pixel from that.
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);
精彩评论