- 浏览: 240310 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
yingjianxuehun:
在android4.4上fb0总是打不开,已经root,权限也 ...
Android原生(Native)C开发之二 framebuffer篇 -
zdyhlp:
新版本4.3.1不能在Android2.2下工作。请问楼主用的 ...
为免费app嵌入Admob广告 -
zdyhlp:
另外要加上ads:adSize="BANNER&qu ...
为免费app嵌入Admob广告 -
zdyhlp:
<com.admob.android.ads.AdVie ...
为免费app嵌入Admob广告 -
王山而:
mark
Android引入第三方jar包的方法
虽然现在能通过交叉环境编译程序,并push到Android上执行,但那只是console台程序,是不是有些单调呢?下面就要看如何通过 Linux的 framebuffer 技术在Android上画图形,关于Linux的framebuffer技术,这里就不再详细讲解了,请大家google一下。
操作framebuffer的主要步骤如下:
1、打开一个可用的FrameBuffer设备;
2、通过mmap调用把显卡的物理内存空间映射到用户空间;
3、更改内存空间里的像素数据并显示;
4、退出时关闭framebuffer设备。
下面的这个例子简单地用framebuffer画了一个渐变的进度条,代码 framebuf.c 如下:
注意,在Android环境,framebuffer设备不是象linux一样的 /dev/fb0,而是 /dev/graphics/fb0 ,
fbfd = open(”/dev/graphics/fb0″, O_RDWR);
打开framebuffer设备,
fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED,
fbfd, 0);
将设备map到一块内存,然后就可以操作这块内存空间来显示你想画的图形了。
最后别忘了关闭设备:
munmap(fbp, screensize);
close(fbfd);
效果图如下:
操作framebuffer的主要步骤如下:
1、打开一个可用的FrameBuffer设备;
2、通过mmap调用把显卡的物理内存空间映射到用户空间;
3、更改内存空间里的像素数据并显示;
4、退出时关闭framebuffer设备。
下面的这个例子简单地用framebuffer画了一个渐变的进度条,代码 framebuf.c 如下:
引用
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
inline static unsigned short int make16color(unsigned char r, unsigned char g, unsigned char b)
{
return (
(((r >> 3) & 31) << 11) |
(((g >> 2) & 63) << 5) |
((b >> 3) & 31) );
}
int main() {
int fbfd = 0;
struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo;
long int screensize = 0;
char *fbp = 0;
int x = 0, y = 0;
int guage_height = 20, step = 10;
long int location = 0;
// Open the file for reading and writing
fbfd = open(”/dev/graphics/fb0″, O_RDWR);
if (!fbfd) {
printf(”Error: cannot open framebuffer device.\n”);
exit(1);
}
printf(”The framebuffer device was opened successfully.\n”);
// Get fixed screen information
if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
printf(”Error reading fixed information.\n”);
exit(2);
}
// Get variable screen information
if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
printf(”Error reading variable information.\n”);
exit(3);
}
printf(”sizeof(unsigned short) = %d\n”, sizeof(unsigned short));
printf(”%dx%d, %dbpp\n”, vinfo.xres, vinfo.yres, vinfo.bits_per_pixel );
printf(”xoffset:%d, yoffset:%d, line_length: %d\n”, vinfo.xoffset, vinfo.yoffset, finfo.line_length );
// Figure out the size of the screen in bytes
screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;;
// Map the device to memory
fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED,
fbfd, 0);
if ((int)fbp == -1) {
printf(”Error: failed to map framebuffer device to memory.\n”);
exit(4);
}
printf(”The framebuffer device was mapped to memory successfully.\n”);
//set to black color first
memset(fbp, 0, screensize);
//draw rectangle
y = (vinfo.yres - guage_height) / 2 - 2; // Where we are going to put the pixel
for (x = step - 2; x < vinfo.xres - step + 2; x++) {
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
(y+vinfo.yoffset) * finfo.line_length;
*((unsigned short int*)(fbp + location)) = 255;
}
y = (vinfo.yres + guage_height) / 2 + 2; // Where we are going to put the pixel
for (x = step - 2; x < vinfo.xres - step + 2; x++) {
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
(y+vinfo.yoffset) * finfo.line_length;
*((unsigned short int*)(fbp + location)) = 255;
}
x = step - 2;
for (y = (vinfo.yres - guage_height) / 2 - 2; y < (vinfo.yres + guage_height) / 2 + 2; y++) {
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
(y+vinfo.yoffset) * finfo.line_length;
*((unsigned short int*)(fbp + location)) = 255;
}
x = vinfo.xres - step + 2;
for (y = (vinfo.yres - guage_height) / 2 - 2; y < (vinfo.yres + guage_height) / 2 + 2; y++) {
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
(y+vinfo.yoffset) * finfo.line_length;
*((unsigned short int*)(fbp + location)) = 255;
}
// Figure out where in memory to put the pixel
for ( x = step; x < vinfo.xres - step; x++ ) {
for ( y = (vinfo.yres - guage_height) / 2; y < (vinfo.yres + guage_height) / 2; y++ ) {
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
(y+vinfo.yoffset) * finfo.line_length;
if ( vinfo.bits_per_pixel == 32 ) {
*(fbp + location) = 100; // Some blue
*(fbp + location + 1) = 15+(x-100)/2; // A little green
*(fbp + location + 2) = 200-(y-100)/5; // A lot of red
*(fbp + location + 3) = 0; // No transparency
} else { //assume 16bpp
unsigned char b = 255 * x / (vinfo.xres - step);
unsigned char g = 255; // (x - 100)/6 A little green
unsigned char r = 255; // A lot of red
unsigned short int t = make16color(r, g, b);
*((unsigned short int*)(fbp + location)) = t;
}
}
//printf(”x = %d, temp = %d\n”, x, temp);
//sleep to see it
usleep(200);
}
//clean framebuffer
munmap(fbp, screensize);
close(fbfd);
return 0;
}
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
inline static unsigned short int make16color(unsigned char r, unsigned char g, unsigned char b)
{
return (
(((r >> 3) & 31) << 11) |
(((g >> 2) & 63) << 5) |
((b >> 3) & 31) );
}
int main() {
int fbfd = 0;
struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo;
long int screensize = 0;
char *fbp = 0;
int x = 0, y = 0;
int guage_height = 20, step = 10;
long int location = 0;
// Open the file for reading and writing
fbfd = open(”/dev/graphics/fb0″, O_RDWR);
if (!fbfd) {
printf(”Error: cannot open framebuffer device.\n”);
exit(1);
}
printf(”The framebuffer device was opened successfully.\n”);
// Get fixed screen information
if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
printf(”Error reading fixed information.\n”);
exit(2);
}
// Get variable screen information
if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
printf(”Error reading variable information.\n”);
exit(3);
}
printf(”sizeof(unsigned short) = %d\n”, sizeof(unsigned short));
printf(”%dx%d, %dbpp\n”, vinfo.xres, vinfo.yres, vinfo.bits_per_pixel );
printf(”xoffset:%d, yoffset:%d, line_length: %d\n”, vinfo.xoffset, vinfo.yoffset, finfo.line_length );
// Figure out the size of the screen in bytes
screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;;
// Map the device to memory
fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED,
fbfd, 0);
if ((int)fbp == -1) {
printf(”Error: failed to map framebuffer device to memory.\n”);
exit(4);
}
printf(”The framebuffer device was mapped to memory successfully.\n”);
//set to black color first
memset(fbp, 0, screensize);
//draw rectangle
y = (vinfo.yres - guage_height) / 2 - 2; // Where we are going to put the pixel
for (x = step - 2; x < vinfo.xres - step + 2; x++) {
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
(y+vinfo.yoffset) * finfo.line_length;
*((unsigned short int*)(fbp + location)) = 255;
}
y = (vinfo.yres + guage_height) / 2 + 2; // Where we are going to put the pixel
for (x = step - 2; x < vinfo.xres - step + 2; x++) {
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
(y+vinfo.yoffset) * finfo.line_length;
*((unsigned short int*)(fbp + location)) = 255;
}
x = step - 2;
for (y = (vinfo.yres - guage_height) / 2 - 2; y < (vinfo.yres + guage_height) / 2 + 2; y++) {
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
(y+vinfo.yoffset) * finfo.line_length;
*((unsigned short int*)(fbp + location)) = 255;
}
x = vinfo.xres - step + 2;
for (y = (vinfo.yres - guage_height) / 2 - 2; y < (vinfo.yres + guage_height) / 2 + 2; y++) {
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
(y+vinfo.yoffset) * finfo.line_length;
*((unsigned short int*)(fbp + location)) = 255;
}
// Figure out where in memory to put the pixel
for ( x = step; x < vinfo.xres - step; x++ ) {
for ( y = (vinfo.yres - guage_height) / 2; y < (vinfo.yres + guage_height) / 2; y++ ) {
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
(y+vinfo.yoffset) * finfo.line_length;
if ( vinfo.bits_per_pixel == 32 ) {
*(fbp + location) = 100; // Some blue
*(fbp + location + 1) = 15+(x-100)/2; // A little green
*(fbp + location + 2) = 200-(y-100)/5; // A lot of red
*(fbp + location + 3) = 0; // No transparency
} else { //assume 16bpp
unsigned char b = 255 * x / (vinfo.xres - step);
unsigned char g = 255; // (x - 100)/6 A little green
unsigned char r = 255; // A lot of red
unsigned short int t = make16color(r, g, b);
*((unsigned short int*)(fbp + location)) = t;
}
}
//printf(”x = %d, temp = %d\n”, x, temp);
//sleep to see it
usleep(200);
}
//clean framebuffer
munmap(fbp, screensize);
close(fbfd);
return 0;
}
注意,在Android环境,framebuffer设备不是象linux一样的 /dev/fb0,而是 /dev/graphics/fb0 ,
fbfd = open(”/dev/graphics/fb0″, O_RDWR);
打开framebuffer设备,
fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED,
fbfd, 0);
将设备map到一块内存,然后就可以操作这块内存空间来显示你想画的图形了。
最后别忘了关闭设备:
munmap(fbp, screensize);
close(fbfd);
效果图如下:
发表评论
-
Android-Intent和PendingIntent的关系
2010-11-05 14:40 7811Intent和PendingIntent的关系 Intent和 ... -
Android引入第三方jar包的方法
2010-03-17 09:09 4422在Android平台中可以使用第三方外部 JAR库文件,在Ec ... -
android的网络接口
2010-02-11 10:07 0目前android平台有3种网各接口可以使用,它们分别是:ja ... -
Google Android SDK 2.1正式发布
2010-02-02 16:45 14241月12日,来自Google Android开发团队博客的消息 ... -
android 常用 INTENT
2010-01-20 23:35 5036IntentFilter 简述:结构化描述int ... -
Google Weather API
2010-01-20 22:10 2231Google Weather API 只支持美国地区使用邮政编 ... -
TableLayout 中 stretchColumns的用法
2010-01-19 16:32 9541<?xml version="1.0" ... -
Android应用开发中的风格和主题(style,themes)
2010-01-19 15:06 2097当你设计你的程序的时候,你可以用风格和主题来统一格式化各种屏幕 ... -
WIFI IP转换
2010-01-14 14:01 1002private String intToIp(int i) { ... -
Get IP Address
2010-01-14 10:43 15071, Connect via WIFI WifiManager ... -
OPhone开发环境设置
2010-01-07 15:16 12971 安装eclipse 3.4.x http://www.e ... -
Android通过AIDL接口实现跨进程通讯
2010-01-07 14:43 2345在Android开发中, 每个应 ... -
对android重力测试的一个疑问
2010-01-04 11:29 1748之前有看过IBM Eyes 关于SensorManager的代 ... -
Android启动过程
2009-12-30 11:07 31701. Boot系统初始化, 具 ... -
android source tree
2009-12-29 15:21 1663makefile 全局makefile bionic b ... -
android绘图坐标
2009-11-23 18:01 2532在android中,手机的屏幕大少为320*480,原点坐标在 ... -
android中绘图的方法
2009-11-23 11:13 2553绘制各种图形、文字使用Canvas类中drawRect、dra ... -
零打碎敲学Android(一)—用什么来替代Graphics
2009-11-23 10:47 2864一、要想在View中绘制图 ... -
Android原生(Native)C开发之三 鼠标事件篇(捕鼠记)
2009-11-20 23:38 2785在做SDL至Android的移植时,键盘事件是能正常捕获到,看 ... -
Android原生(Native) C开发之一 环境搭建篇
2009-11-20 23:31 1569Android是基于Linux的操作系统,处理器是ARM的,所 ...
相关推荐
android下读取framebuffer的内容 程序运行就会把framebuffer的内容保存在/sdcard/123.raw下面, 要想打开还需要在文件上插入如bitmap的文件头即可
QUALCOMM 平台 android framebuffer 命令行测试工具 源代码
linux下基于framebuffer运行,运行前先将framebuffer设置为16位色.
framebuffer驱动全篇
一个完整的android framebuffer截图程序。支持16位和24位,支持所有屏幕大小。比上一个版本多了对屏幕指定部位进行截图的功能。
Android4.0下使用framebuffer抓屏并保存成bmp文件
在手机root下,通过Framebuffer获取手机系统界面上的截图,可以显示出来
一个完整的android framebuffer截图程序。支持16位和24位,支持所有屏幕大小。
总部设在南加州、专注于Android平台并提供其移动应用开发及解决方案的迈奔无线(mAPPn Inc.)也投入技术和人力参与了本书的工作。 参与本书编写的还有于仕林、张宇、张超等人,赵家维、黄亮、沈桢、徐威特、杨钰等...
一个完整的android framebuffer截图程序。支持16位、24位和32位,支持所有屏幕大小。16位和32位的全部功能经测试,可以完美使用。24位暂时没有测试过。
framebuffer测试程序,帮你了解framebuffer流程
framebuffer驱动全篇.docframebuffer驱动全篇.doc
S3C2440上LCD驱动(FrameBuffer)实例开发讲解
在Linux内核中,Framebuffer(帖缓冲)驱动是显示驱动的标准,Framebuffer将显示设备抽象为帖缓冲区,用户通过内存映射到进程地址空间之后,就可以直接进行读写操作,且写操作可以立即在屏幕上进行显示,在Linux内核/...
第一篇Android的前世今生——Android概述篇 第1章Android的前世今生 1.1 Android的起源 1.2开放手机联盟 1.3开源与相关协议 1.4系统的升级与发展 第2章Android体系结构 2.1四层空间基本结构 2.1.1 Android系统底层...
通过LCD控制器就可以产生LCD驱动器所需要的控制信号来控制STN/TFT屏了。
某网友整理的 framebuffer驱动全篇.doc 我转成了pdf,方便更多人的阅读。
framebuffer.c
介绍了linux在s3c2410中framebuffer移植过程
1.1.1 android开发系统的由来 1 1.1.2 移动电话系统开发模式 2 1.1.3 未来移动电话的功能及android的优势 4 1.2 android的开发工作 6 1.2.1 android移植开发 6 1.2.2 android应用开发 8 1.2.3 android系统开发 9 1.3...