<h2 class="titName SG_txta" style="">Android下截屏 及 格式转换</h2>
/dev/graphics/fb0 fb0
dd bs=$((320*320*2)) count=2 if=fb0 of=screenshot1.xmp
./565to888 <screenshot1.xmp >screenshot888.xmp
convert -depth 8 -size 216x204 rgb:screenshot888.xmp screenshot888.png
#display /tmp/screenshot888.png
http://wiseideal.iteye.com/blog/1250175
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
int version = 0;
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;
long 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("id %s\n",finfo.id); //s3c2410fb
printf("smem_start %ld\n",finfo.smem_start); //帧缓冲 内存开始地址,物理地址
printf("smem_len %d\n",finfo.smem_len); // 帧缓冲 内存 长度
printf("type %d\n",finfo.type);
printf("type_aux %d\n",finfo.type_aux);//平面交织交替
printf("visual %d\n",finfo.visual); //记录 色彩模式 2
printf("xpanstep %d\n",finfo.xpanstep);//如果没有硬件panning,赋0
printf("ypanstep %d\n",finfo.ypanstep);
printf("line_length %d\n",finfo.line_length); //640
printf("mmio_start %ld\n",finfo.mmio_start);//内存映射IO开始地址 物理地址
printf("mmio_len %d\n",finfo.mmio_len);//内存映射IO 长度
printf("accel %d\n\n",finfo.accel);
printf("xres %d\n",vinfo.xres); //可见解析度 320
printf("yres %d\n",vinfo.yres); //240
printf("xres_virturl %d\n",vinfo.xres_virtual); //虚拟解析度 320
printf("yres_virtual %d\n",vinfo.yres_virtual); //240
printf("xoffset %d\n",vinfo.xoffset); //虚拟到可见的偏移 0
printf("yoffset %d\n",vinfo.yoffset); // 0
printf("bits_per_pixel %d\n",vinfo.bits_per_pixel); //每像素位数 bpp 16
printf("grayscale %d\n",vinfo.grayscale);//非零时,指灰度
printf("fb_bitfield red.offset %d\n",vinfo.red.offset); //11 偏移11位
printf("fb_bitfield .length %d\n",vinfo.red.length); // 5
printf("fb_bitfield .msb_right %d\n",vinfo.red.msb_right); // 0
printf("fb_bitfield green.offset %d\n",vinfo.green.offset); //5 偏移5位
printf("fb_bitfield .length %d\n",vinfo.green.length); // 6
printf("fb_bitfield .msb_right %d\n",vinfo.green.msb_right); // 0
printf("fb_bitfield blue.offset %d\n",vinfo.blue.offset);
printf("fb_bitfield .length %d\n",vinfo.blue.length);
printf("fb_bitfield .msb_right %d\n",vinfo.blue.msb_right);
printf("fb_bitfield transp.offset %d\n",vinfo.transp.offset);
printf("fb_bitfield .length %d\n",vinfo.transp.length);
printf("fb_bitfield .msb_right %d\n",vinfo.transp.msb_right);
printf("nonstd %d\n",vinfo.nonstd); //!=0 非标准像素格式
printf("activate %d\n",vinfo.activate);
printf("height %d\n",vinfo.height); //高度/ 240
printf("widht %d\n",vinfo.width); // 320
printf("accel_flags %d\n",vinfo.accel_flags); //看 fb_info.flags
//定时,除了 pixclock之外,其他的都以像素时钟为单位
printf("pixclock %d\n",vinfo.pixclock);//像素时钟,皮秒 80000
printf("left_margin %d\n",vinfo.left_margin);//行切换:从同步到绘图之间的延迟 28
printf("right_margin %d\n",vinfo.right_margin);//行切换:从绘图到同步之间的延迟 24
printf("upper_margin %d\n",vinfo.upper_margin);//帧切换:从同步到绘图之间的延迟 6
printf("lower_margin %d\n",vinfo.lower_margin);//帧切换:从绘图到同步之间的延迟 2
printf("hsync_len %d\n",vinfo.hsync_len); //hor 水平同步的长度 42
printf("vsync_len %d\n",vinfo.vsync_len); //vir 垂直同步的长度 12
printf("sync %d\n",vinfo.sync); //
printf("vmode %d\n",vinfo.vmode);
printf("rotate %d\n",vinfo.rotate);
// Figure out the size of the screen in bytes
screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;;
printf("screensize = %ld\n", screensize);
// Map the device to memory
fbp = (char *)mmap(0, screensize*2, PROT_READ | PROT_WRITE, MAP_SHARED,
fbfd, 0);
if ((int)fbp == -1) {
printf("Error: failed to map framebuffer device to memory.\n");
exit(4);
}
printf("The framebuffer device was mapped to memory successfully.\n");
/*
printf("White Screen\n");
//while(1)
{
for(x =0;x<640*5;x+=2)
{
*((unsigned short int*)(fbp + x)) = 0xffff;
}
usleep(200);
}
for(x =0;x<640;x+=2)
{
y =*((unsigned short int*)(fbp + x));
printf("x = %lx, temp = %lx\n", x, y);
}
*/
//set to black color first
memset(fbp, 0, screensize);
//draw rectangle
y = (vinfo.yres - guage_height) / 2 - 2; // Where we are going to put the pixel
for (x = step - 2; x < vinfo.xres - step + 2; x++) {
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
(y+vinfo.yoffset) * finfo.line_length;
*((unsigned short int*)(fbp + location)) = 255;
}
y = (vinfo.yres + guage_height) / 2 + 2; // Where we are going to put the pixel
for (x = step - 2; x < vinfo.xres - step + 2; x++) {
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
(y+vinfo.yoffset) * finfo.line_length;
*((unsigned short int*)(fbp + location)) = 255;
}
x = 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;
}
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 = %ld\n", x, location);
//sleep to see it
usleep(200);
}
//clean framebuffer
munmap(fbp, screensize);
close(fbfd);
version =16;
printf("version %d %s\n",version,__TIME__);
return 0;
}
http://blog.youkuaiyun.com/louiswangbing/article/details/6655040