一.android下读取framebuffer的内容
1. 读取
读取framebuffer跟linux下读取区别不大,只不过linux下是/dev/fb0, android下是/dev/graphics/fb0.
-
int capture()
-
{
-
int fd = 0;
-
FILE *out_file;
-
-
struct fb_var_screeninfo vinfo;
-
struct fb_fix_screeninfo finfo;
-
-
long int screensize = 0;
-
struct fb_bitfield red;
-
struct fb_bitfield green;
-
struct fb_bitfield blue;
-
-
if ((out_file = fopen("/sdcard/123.raw", "w+")) == NULL)
-
LOGME("open file error\n");
-
-
fd = open("/dev/graphics/fb0", O_RDWR);
-
-
ioctl(fd, FBIOGET_FSCREENINFO, &finfo);
-
ioctl(fd, FBIOGET_VSCREENINFO, &vinfo);
-
-
int xres = vinfo.xres;
-
int yres = vinfo.yres;
-
int bits_per_pixel = vinfo.bits_per_pixel;
-
screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
-
char * fb_mem = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
-
fwrite(fb_mem, screensize, 1, out_file);
-
munmap(fb_mem, screensize);
-
close(fd);
-
return 0;
-
-
}
2. 区别
a. 跟linux差别最大的是权限设置
工程的AndroidManifest.xml如下:
-
<?xml version="1.0" encoding="utf-8"?>
-
<manifest xmlns:android=""
-
package="com.capture"
-
android:versionCode="1"
-
android:versionName="1.0"
-
>
-
<uses-sdk android:minSdkVersion="14" />
-
<application android:label="@string/app_name"
-
android:debuggable="true">
-
<activity android:name="com.capture.Capture"
-
android:label="@string/app_name">
-
<intent-filter>
-
<action android:name="android.intent.action.MAIN" />
-
<category android:name="android.intent.category.LAUNCHER" />
-
</intent-filter>
-
</activity>
-
</application>
-
<uses-permission android:name="android.permission.INTERNET" />
-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
-
<uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER"/>
-
<uses-permission android:name="android.permission.READ_FRAME_BUFFER"/>
-
</manifest>
b. 还需要关键的一步
修改了AndroidManifest.xml之后,还是会在open
("/dev/graphics/fb0", O_RDWR
); 时报错
再加上这一步就ok了.
-
adb shell chmod 777 /dev/graphics/fb0
二.附录
1. 在xml中加上READ_FRAME_BUFFER报错的解决方法
-
在AndroidManifest.xml中加入如下:
-
<uses-permission android:name="android.permission.READ_FRAME_BUFFER" />
-
会报错: Permission is only granted to system app
-
解决方法:
-
Window -> Preferences -> Android -> Lint Error Checking.
-
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?
各位大爷给点面子,点一下让我赚点小分,好不好? 只要一分,评论一下就可以了)
阅读(458) | 评论(0) | 转发(0) |