Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1306513
  • 博文数量: 860
  • 博客积分: 425
  • 博客等级: 下士
  • 技术积分: 1464
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-20 19:57
个人简介

对技术执着

文章分类

全部博文(860)

文章存档

2019年(16)

2018年(12)

2015年(732)

2013年(85)

2012年(15)

我的朋友

分类: Android平台

2015-10-15 09:35:53

一.android下读取framebuffer的内容
1. 读取
读取framebuffer跟linux下读取区别不大,只不过linux下是/dev/fb0, android下是/dev/graphics/fb0.
  1. int capture()
  2. {
  3.     int fd = 0;
  4.     FILE *out_file;

  5.     struct fb_var_screeninfo vinfo;
  6.     struct fb_fix_screeninfo finfo;

  7.     long int screensize = 0;
  8.     struct fb_bitfield red;
  9.     struct fb_bitfield green;
  10.     struct fb_bitfield blue;

  11.     if ((out_file = fopen("/sdcard/123.raw", "w+")) == NULL)
  12.         LOGME("open file error\n");

  13.     fd = open("/dev/graphics/fb0", O_RDWR); 

  14.     ioctl(fd, FBIOGET_FSCREENINFO, &finfo);
  15.     ioctl(fd, FBIOGET_VSCREENINFO, &vinfo);

  16.     int xres = vinfo.xres;
  17.     int yres = vinfo.yres;
  18.     int bits_per_pixel = vinfo.bits_per_pixel;
  19.     screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8; 
  20.     char * fb_mem = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); 
  21.     fwrite(fb_mem, screensize, 1, out_file);
  22.     munmap(fb_mem, screensize);
  23.     close(fd);
  24.     return 0;

  25. }
2. 区别
a. 跟linux差别最大的是权限设置
工程的AndroidManifest.xml如下:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android=""
  3.       package="com.capture"
  4.       android:versionCode="1"
  5.       android:versionName="1.0"
  6.       >
  7.     <uses-sdk android:minSdkVersion="14" />
  8.     <application android:label="@string/app_name"
  9.                  android:debuggable="true">
  10.         <activity android:name="com.capture.Capture"
  11.                   android:label="@string/app_name">
  12.             <intent-filter>
  13.                 <action android:name="android.intent.action.MAIN" />
  14.                 <category android:name="android.intent.category.LAUNCHER" />
  15.             </intent-filter>
  16.         </activity>
  17.     </application>
  18. <uses-permission android:name="android.permission.INTERNET" />
  19. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  20. <uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER"/>
  21. <uses-permission android:name="android.permission.READ_FRAME_BUFFER"/>
  22. </manifest>
b. 还需要关键的一步
修改了AndroidManifest.xml之后,还是会在open("/dev/graphics/fb0", O_RDWR); 时报错
再加上这一步就ok了.
  1. adb shell chmod 777 /dev/graphics/fb0
二.附录
1. 在xml中加上READ_FRAME_BUFFER报错的解决方法
  1. 在AndroidManifest.xml中加入如下:
  2. <uses-permission android:name="android.permission.READ_FRAME_BUFFER" />
  3. 会报错: Permission is only granted to system app
  4. 解决方法:
  5. Window -> Preferences -> Android -> Lint Error Checking.
  6. In the list find an entry with ID = ProtectedPermission. Set the Severity to something lower than Error. This way you can still compile the project using Eclipse.
参考文章:


完整的代码下载:
( cu上的代码怎么会是在csdn?
  各位大爷给点面子,点一下让我赚点小分,好不好? 只要一分,评论一下就可以了)

阅读(7180) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~