如何获取缓冲区获取缓冲区屏幕设备android

时间:2015-03-04 11:07:05

标签: android screen buffer device

我有一个函数get buffer screen device android

struct fb_var_screeninfo scrinfo;
struct fb_fix_screeninfo fscrinfo;

int initFB(void)
{  
  L("--Initializing framebuffer access method--\n");

  fbmmap = MAP_FAILED;

  if ((fbfd = open("/dev/graphics/fb0", O_RDWR)) == -1) { 
    L("Cannot open fb device %s\n", framebuffer_device);
    sendMsgToGui("~SHOW|Cannot open fb device, please try out other display grab method\n");
    return -1;
  }

  update_fb_info();


  if (ioctl(fbfd, FBIOGET_FSCREENINFO, &fscrinfo) != 0) {
    L("ioctl error\n");
    return -1;
  }

  L("line_lenght=%d xres=%d, yres=%d, xresv=%d, yresv=%d, xoffs=%d, yoffs=%d, bpp=%d\n",
    (int)fscrinfo.line_length,(int)scrinfo.xres, (int)scrinfo.yres,
    (int)scrinfo.xres_virtual, (int)scrinfo.yres_virtual,
    (int)scrinfo.xoffset, (int)scrinfo.yoffset,
    (int)scrinfo.bits_per_pixel);

  size_t size = scrinfo.yres_virtual;
  if (size < scrinfo.yres * 2) {
    L("Using Droid workaround\n");
    size = scrinfo.yres * 2;
  }

  if ((scrinfo.bits_per_pixel == 24)) {
    scrinfo.bits_per_pixel = 32;
    L("24-bit XRGB display detected\n");
  }

  size_t fbSize = roundUpToPageSize(fscrinfo.line_length * size);

  fbmmap = mmap(NULL, fbSize , PROT_READ|PROT_WRITE ,  MAP_SHARED , fbfd, 0);

  if (fbmmap == MAP_FAILED) { 
    L("mmap failed\n");
    sendMsgToGui("~SHOW|Framebuffer mmap failed, please try out other display grab method\n");
    return -1;
  }

  return 1;
}

它适用于xperia u,但它会返回带有nexus 10和samsung galaxy tab 3的黑屏。 可以帮助我获得缓冲屏的好处吗?

谢谢

1 个答案:

答案 0 :(得分:-1)

我会使用screencap:

adb shell screencap –p /data/screen.png
adb pull /data/screen.png

它会返回当前显示的屏幕的PNG图像。 screencap是Android内置的实用程序。