打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
FrameBuffer编程二(简单程序下)

1、开发平台sc6410,编译器arm-linux-gcc 4.3

以下为源代码:

#include <fcntl.h> 
#include <sys/ioctl.h> 
#include <sys/types.h> 
#include <sys/stat.h> 
#include <sys/mman.h> 
#include <unistd.h> 
#include <string.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <string.h> 
#include <linux/types.h> 
#include <linux/fb.h> 
#include <linux/videodev2.h>

int main(int argc ,char *argv[]) 

    int fbfd = 0; 
    struct fb_var_screeninfo vinfo; 
    struct fb_fix_screeninfo finfo; 
    long int screensize = 0; 
    char *fbp = NULL; 
    int x = 0 , y = 0; 
    long int location = 0 ; 
    int sav = 0;

//open framebuffer device 
    fbfd = open("/dev/fb0",O_RDWR); 
    if(!fbfd){ 
            printf("Error:cannot open the framebuffer device!\n"); 
            exit(1); 
        }    
    printf("well you open the framebuffer sucessful!\n"); 
//get the fixed screen information 
    if(ioctl(fbfd,FBIOGET_FSCREENINFO,&finfo)){ 
            printf("Error reading fixed information\n"); 
            exit(2); 
        } 
//get the variable screen information 
    if(ioctl(fbfd,FBIOGET_VSCREENINFO,&vinfo)){ 
            printf("Error reading variable information\n"); 
            exit(3); 
        } 
//show these information 
    printf("vinfo.xres=%d\n",vinfo.xres); 
    printf("vinfo.yres=%d\n",vinfo.yres); 
    printf("vinfo.bit_per_bits=%d\n",vinfo.bits_per_pixel); 
    printf("vinfo.xoffset=%d\n",vinfo.xoffset); 
    printf("vinfo.yoffset=%d\n",vinfo.yoffset); 
    printf("finfo.line_length=%d\n",finfo.line_length);    
    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); 
    } 
    memset(fbp,0,screensize); 
//plot the screen the colour for black 
    for(x=0;x<vinfo.xres;x++) 
        for(y=0;y<vinfo.yres;y++){ 
            location =(x+vinfo.xoffset)*(vinfo.bits_per_pixel/8)+(y+vinfo.yoffset)*finfo.line_length; 
            *(fbp+location)=0xFF; 
            *(fbp+location+1)=0x00; 
            }    
    sleep(10); 
//release the memory 
    munmap(fbp,screensize); 
    close(fbfd); 
    return 0; 
}

编译下载到开发板上运行的结果截图为(而你的开发板的显示屏会变蓝色):

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
framebuffer应用程序编写
对FrameBuffer的一夜hack。。。
framebuffer编程显示真彩图片
直接写framebuffer
在Framebuffer下编程显示BMP图象
framebuffer 和skia 结合搭建GUI
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服