open(\"/dev/graphics/fb0\") failed!

转自VC错误:http://www.vcerror.com/?p=2160
问题描述:

在用手机app通过framebuffer截屏的时候,手机已经root过了,但是执行代码:
fb->fd = open("/dev/graphics/fb0", O_RDONLY);
还是返回失败


解决方法:
具体的解决方法参考文章:http://www.vcerror.com/?p=2160
打开/dev/fb0文件通常用于在Linux系统中访问帧缓冲设备。如果要在多个线程中访问此设备,则可以使用线程安全的方法打开该设备。下面是一个示例代码: ```c #include <fcntl.h> #include <sys/mman.h> #include <sys/ioctl.h> #include <linux/fb.h> #include <pthread.h> void *fb_thread(void *arg) { int fbfd = open("/dev/fb0", O_RDWR); if (fbfd == -1) { perror("Error: cannot open framebuffer device"); exit(1); } struct fb_fix_screeninfo finfo; if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) { perror("Error reading fixed information"); exit(2); } struct fb_var_screeninfo vinfo; if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) { perror("Error reading variable information"); exit(3); } long screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8; void *fbp = mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0); if ((intptr_t)fbp == -1) { perror("Error: failed to map framebuffer device to memory"); exit(4); } // 进行帧缓冲操作... munmap(fbp, screensize); close(fbfd); return NULL; } int main() { pthread_t t1, t2; pthread_create(&t1, NULL, fb_thread, NULL); pthread_create(&t2, NULL, fb_thread, NULL); pthread_join(t1, NULL); pthread_join(t2, NULL); return 0; } ``` 上述代码使用了 pthread 库来创建两个线程,每个线程都打开了/dev/fb0设备,并进行了一些帧缓冲操作。注意,这里使用了 mmap() 函数将帧缓冲设备映射到内存中,以便进行读写操作。在程序结束时,使用 munmap() 函数将内存映射释放。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值