WEB开发网
开发学院手机开发Android 开发 Android操作framebuffer 阅读

Android操作framebuffer

 2010-05-31 14:42:00 来源:WEB开发网   
核心提示:}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

}

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 ", 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);

上一页  1 2 3 

Tags:Android 操作 framebuffer

编辑录入:coldstar [复制链接] [打 印]
赞助商链接