Day 63 linux 下绘制屏幕

本文介绍如何在Linux环境下,通过打开帧缓冲设备文件/dev/fb0,并使用mmap函数进行内存映射,实现对屏幕的直接绘图操作。代码示例中,通过无限循环在屏幕中央设置了一个红色像素点。

//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;

}

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值