请问,linux下C/C++怎么获取屏幕分辨率?(不使用Qt和GTK)

 我来答
chzhq2009
2011-05-21 · TA获得超过262个赞
知道答主
回答量:33
采纳率:100%
帮助的人:39.9万
展开全部
把这个程序运行下字符终端下到分辨率就出来了。
#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;
}
如有问题联系我!
sparkaround
推荐于2016-11-21 · TA获得超过3508个赞
知道大有可为答主
回答量:1522
采纳率:0%
帮助的人:958万
展开全部
直接用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);
追问
我们需要跨平台,不能使用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.
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式