fbsnapshot, 无敌截图玩具
时间:2007-01-06 来源:hellwolf
fbsnapshot.c :
Makefile :
截图实例:
zhcon:

directFB, wm是default的:
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdio.h>
#include <linux/fb.h>
#include <gd.h>
int main(void){
int fbfd;
int i;
struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo;
int screensize;
int bp;
unsigned char* fbp;
gdImagePtr im;
FILE *out;
fbfd = open("/dev/fb", O_RDWR);
ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo);
ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo);
bp = vinfo.bits_per_pixel/8;
screensize = vinfo.xres*vinfo.yres;
fbp = mmap(NULL, screensize*bp, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
printf("%ux%u@%ubpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
im = gdImageCreateTrueColor(vinfo.xres, vinfo.yres);
out = fopen("fbsnapshot.png", "wb");
switch(bp){
case 4:
for(i = 0; i < screensize; ++i){
gdImageSetPixel(im, i%vinfo.xres, i/vinfo.xres,
gdImageColorAllocate(im,
fbp[4*i + 2],
fbp[4*i + 1],
fbp[4*i + 0]));
}
break;
default:
printf("Unhandled bpp %d\n", bp);
}
gdImagePng(im, out);
fclose(out);
gdImageDestroy(im);
}
Makefile :
fbsnapshot : fbsnapshot.c
gcc $(gdlib-config --cflags) $(gdlib-config --libs) -lgd $< -o $@
截图实例:
zhcon:

directFB, wm是default的:

相关阅读 更多 +