读取屏幕的一个像素(即您现在可以看到的1024*768)
在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;
}
,但屏幕似乎为空,
抱歉新手问题
,但有人可以让我知道如何访问帧缓冲区来读取像素吗?
欢迎任何可能的方式
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SDL 不允许您读取桌面的像素。它抽象了这些功能,因为它们是不可移植的(例如,在控制台或嵌入式设备上读取桌面像素意味着什么?)因此,您将需要直接使用 Windows API。我已经有一段时间没有使用 Windows 了,但至少在几年前,该过程的工作原理如下:
获取桌面设备上下文。
从中读取像素。
例如,代码可能看起来像这样(粗略地说,我不再使用 Windows,所以我在这里不是 100%):
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):