1. 程式人生 > >linux c 獲取螢幕解析度程式

linux c 獲取螢幕解析度程式

把這個程式執行下字元終端下到解析度就出來了。
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <math.h>

int w,h ,bpp;

int *fbmem;

int main(int argc , char *argv[])
{
int fd;
struct fb_var_screeninfo fb_var;

fd = open("/
dev
/fb0",O_RDWR);
//
//screen w , h , bpp
//get screen information
ioctl (fd,FBIOGET_VSCREENINFO,&fb_var);
w = fb_var.xres;
h = fb_var.yres;
bpp = fb_var.bits_per_pixel;
printf ("Framebuffer %d*%d-%dbpp\n",w,h,bpp);

//fbmem = Framebuffer address
fbmem = mmap (0,w*h*bpp/8,PROT_WRITE|PROT_READ,
MAP_SHARED,fd,0);
//y = 10,x = 200, color = 0xF800;

return 0;
}