图形-获取屏幕的分辨率

一、

 

 

 

 

二、

1、在图形驱动还是fb时,在/sys/class/graphics/fb0获取。

cat mode

cat modes,查看支持的分辨率

2、通过fb驱动向上引出的接口获取


#include 
#include 
#include 



int GetFbResolution(int number, int *width, int *height) {

	//int ret = 0;
	int fd;
	struct fb_var_screeninfo fb_var;
	char deviceName[20];
	char deviceNumber[2];
	
	if (number <0) {
		printf("input error fb number.\n");
		return -1;
	}

	strcpy(deviceName,"/dev/graphics/fb");
	deviceNumber[0] = '0' + (number - 0);
	deviceNumber[1] = 0;
	strcat(deviceName, deviceNumber);
	
	printf("to open %s.\n",deviceName);
	
	if ((fd = open(deviceName, O_RDWR, 0)) < 0 ) {
		printf("unable to open %s.\n",deviceName);
		return -1;
	}
	
	if (ioctl(fd,FBIOGET_VSCREENINFO,&fb_var) < 0) {
		printf("get fb var info failed.\n");
		close(fd);
		return -1;
	}
	close(fd);
	*width = fb_var.xres;
	*height = fb_var.yres;
	
	printf("fb%d: x=%d, y=%d.\n",number,*width,*height);
	
	return 0;
}


int main() {

	int width = 0;
	int height = 0;
	
	GetFbResolution(3,&width,&height);
	
	return 0;
}

 

 

三、总结

你可能感兴趣的:(Android图形系统)