易截截图软件、单文件、免安装、纯绿色、仅160KB

Android原生(Native)C开发之二 framebuffer篇


如对Android原生(Natvie)C开发还任何疑问,请参阅http://emck.avaw.com/?p=205
虽然现在能通过交叉环境编译程序,并push到Android上执行,但那只是console台程序,是不是有些单调呢?下面就要看如何通过Linux的 framebuffer 技术在Android上画图形,关于Linux的framebuffer技术,这里就不再详细讲解了,请大家google一下。
操作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


相关文档:

c函数的参数传递

在C语言中,所有传递给函数的参数都是按值传递的。
#include <iostream>
using namespace std;
void Out(int* p)
{
    int j = 11;
    p = &j;
    *p = 12;
    cout<<*p<<endl;
}
int main(int argc,char*argv[])
{
&n ......

C typedef详解及与#define的区别

typedef 声明,简称 typedef,为现有类型创建一个新的名字。比如人们常常使用 typedef 来编写更美观和可读的代码。所谓美观,意指 typedef 能隐藏笨拙的语法构造以及平台相关的数据类型,从而增强可移植性和以及未来的可维护性。
第一、四个用途
用途一:
定义一种类型的别名,而不只是简单的宏替换。可以用作同时声明指 ......

yichi的c代码书写规范

//yichi的c代码编写规范:091216
//一、常量:
//  所有宏定义、枚举常数和const变量全部由大写字母构成,词与词之间用下划线分开,例如#define GPS_WORK_STATUS 0x30
//二、变量:
//  局部变量全部由小写字母构成,词与词之间用下划线分开,例如uint8 ack_delay_time[4];全局变量与局部变量 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号