易截截图软件、单文件、免安装、纯绿色、仅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之一,简单函数调用

简单的函数调用,通过简单的函数调用反汇编可以清楚了解如下
1.栈到底是什么,如何操纵栈的?
2.参数和临时变量是以什么形式在哪存放?
3.如何传递返回值?
举例:
#include <stdio.h>
int add(int a,int b)
{
     int c=0;
     c=a+b;
     ......

Visual C++中的C运行时库浅析(lib dll)

Visual C++中的C运行时库浅析(lib dll)
一、历史
  C运行时库就是C run-time library,诞生于20世纪70年代,是C而非C++语言世界的概念,C程序运行时需要这些库中的函数。
  C语言是所谓的“小内核”语言,就其语言本身来说很小(不多的关键字,程序流程控制,数据类型等)。所以,C语言内核开发出来之后, ......

C 运行时错误 R6002

如下代码编译运行就会提示R6002错误 #include
struct xxx{
  float score;
};
int main()
{
  xxx* p = new xxx;
  scanf( "%f" , &p->score );
  delete p;
} 解决方案很简单 int main()
{
  xxx* p ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号