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
相关文档:
from:邹鑫的专栏
什么时候需要创建线程池呢?简单的说,如果一个应用需要频繁的创建和销毁线程,而任务执行的时间又非常短,这样线程创建和销毁的带来的开销就不容忽视,这时也是线程池该出场的机会了。如果线程创建和销毁时间相比任务执行时间可以忽略不计,则没有必要使用线程池了。
&n ......
1.scanf格式符 p9
ld long
lf double
2.三字母词 p22
为了表示一些特殊的字符,在老式的机器键盘中可能没有的字符,特别约定了一种三字母词,三字母词都以??开始,如下:
??( &nb ......
C/C++招聘的一些感受和经验[转]
前段时间刚参加了n多公司的C/C++软件工程师的面试,有国企,外企,私企(moto,飞思卡尔,港湾,中国卫星XXX(这个牛))等等等等。感受感想颇多,近日终于空闲,在此表述一下。
本人基本条件:3年开发经验,2year+ Windows development experence,1 ......
#include<stdio.h>
#include<math.h>
#define u 20
int i,j,n,m;
float Ix[u],I[u][u],H_X,H_Y,H_XY,I_XY,H_XpY,Pypx[u][u],Px[u],H_YpX,Py[u],Pxpy[u][u],Pxy[u][u];
/*定义的Ix[]=I(x[i])自信息;I[][]=I(x[i];y[j])互信息;H_X=H(X)平均自信息;H_XY=H(XY)联合熵;
I_XY=I(X;Y)平均互信息;H_XpY=H(X|Y ......
在VS中写SQL语句的时候,千万万千要小心再小心,比如 说 数据类型的匹配, 单引号(这个能把人迷死)
where 子句中可千万不能有空格(当查询条件为字符串的时候能把你弄疯,我弄这个的时候都疯了几次了,什么都对就是查不出来,调试了N遍才发现。)不行了,吃饭去,再不吃看见活人都想咬了。 ......