
请问,linux下C/C++怎么获取屏幕分辨率?(不使用Qt和GTK)
展开全部
把这个程序运行下字符终端下到分辨率就出来了。
#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;
}
如有问题联系我!
#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;
}
如有问题联系我!
展开全部
直接用xlib:
char *display_name = getenv("DISPLAY");
unsigned int display = XOpenDisplay(display_name);
int screen_num = DefaultScreen(display);
unsigned int display_width = DisplayWidth(display, screen_num);
unsigned int display_height = DisplayHeight(display, screen_num);
printf("w=%d h=%d\n", display_width, display_height);
char *display_name = getenv("DISPLAY");
unsigned int display = XOpenDisplay(display_name);
int screen_num = DefaultScreen(display);
unsigned int display_width = DisplayWidth(display, screen_num);
unsigned int display_height = DisplayHeight(display, screen_num);
printf("w=%d h=%d\n", display_width, display_height);
追问
我们需要跨平台,不能使用xwindow,请问使用curses库应该怎么实现?或者其他的,不适用xwidow、qt、Gtk的
追答
console下的分辨率?framebuffer? 如果要字符宽度和高度,用ncurses的LINES和COLS:
The integer variables LINES and COLS are defined in and will
be filled in by initscr with the size of the screen.
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |