//linux 下绘制屏幕,打开屏幕,再用mmap函数映射内存
#include<stdio.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include<stdlib.h>
int main(int argc, const char *argv[])
{
//1 open screen
//2 mmap,内存映射
//write();
//close();
int fb = open("/dev/fb0",O_RDWR );
if(-1== fb)
{
perror(" open fb0 ");
exit(1);
}
unsigned int * pmem =mmap(NULL,800*480*4,PROT_WRITE|PROT_READ,MAP_SHARED,fb,0);
unsigned int * p;//临时指针,
while(1)
{
int x =400;
int y =240;
p=pmem+ x+y*800;
*p=0x00ff0000; //0x00000000;
}
close(fb);
return 0;
}
本文介绍如何在Linux环境下,通过打开帧缓冲设备文件/dev/fb0,并使用mmap函数进行内存映射,实现对屏幕的直接绘图操作。代码示例中,通过无限循环在屏幕中央设置了一个红色像素点。
1770

被折叠的 条评论
为什么被折叠?



