`
yanlijun250
  • 浏览: 750082 次
文章分类
社区版块
存档分类
最新评论

Android屏幕截图实现 (adbd部分)

 
阅读更多

Android屏幕截图实现(手记)

/android2.1/system/core/adb/framebuffer_service.c这个里面是DDMS 里面截图通信adbd进程的代码 DDMS那边接到的数据是用JAVA处理的!framebuffer_service.c代码如下:

/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the “License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an “AS IS” BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>

#include “fdevent.h”
#include “adb.h”

#include <linux/fb.h>
#include <sys/ioctl.h>
#include <sys/mman.h>

/* TODO:
** – sync with vsync to avoid tearing
*/
/* This version number defines the format of the fbinfo struct.
It must match versioning in ddms where this data is consumed. */
#define DDMS_RAWIMAGE_VERSION 1
struct fbinfo {
unsigned int version;
unsigned int bpp;
unsigned int size;
unsigned int width;
unsigned int height;
unsigned int red_offset;
unsigned int red_length;
unsigned int blue_offset;
unsigned int blue_length;
unsigned int green_offset;
unsigned int green_length;
unsigned int alpha_offset;
unsigned int alpha_length;
} __attribute__((packed));

void framebuffer_service(int fd, void *cookie)
{
struct fb_var_screeninfo vinfo;
int fb, offset;
char x[256];

struct fbinfo fbinfo;
unsigned i, bytespp;

fb = open(“/dev/graphics/fb0″, O_RDONLY);
if(fb < 0) goto done;

if(ioctl(fb, FBIOGET_VSCREENINFO, &vinfo) < 0) goto done;
fcntl(fb, F_SETFD, FD_CLOEXEC);

bytespp = vinfo.bits_per_pixel / 8;

fbinfo.version = DDMS_RAWIMAGE_VERSION;
fbinfo.bpp = vinfo.bits_per_pixel;
fbinfo.size = vinfo.xres * vinfo.yres * bytespp;
fbinfo.width = vinfo.xres;
fbinfo.height = vinfo.yres;
fbinfo.red_offset = vinfo.red.offset;
fbinfo.red_length = vinfo.red.length;
fbinfo.green_offset = vinfo.green.offset;
fbinfo.green_length = vinfo.green.length;
fbinfo.blue_offset = vinfo.blue.offset;
fbinfo.blue_length = vinfo.blue.length;
fbinfo.alpha_offset = vinfo.transp.offset;
fbinfo.alpha_length = vinfo.transp.length;

/* HACK: for several of our 3d cores a specific alignment
* is required so the start of the fb may not be an integer number of lines
* from the base. As a result we are storing the additional offset in
* xoffset. This is not the correct usage for xoffset, it should be added
* to each line, not just once at the beginning */
offset = vinfo.xoffset * bytespp;

offset += vinfo.xres * vinfo.yoffset * bytespp;

if(writex(fd, &fbinfo, sizeof(fbinfo))) goto done;

lseek(fb, offset, SEEK_SET);
for(i = 0; i < fbinfo.size; i += 256) {
if(readx(fb, &x, 256)) goto done;
if(writex(fd, &x, 256)) goto done;
}

if(readx(fb, &x, fbinfo.size % 256)) goto done;
if(writex(fd, &x, fbinfo.size % 256)) goto done;

done:
if(fb >= 0) close(fb);
close(fd);
}

用framebuffer截屏,就是把当前framebuffer的内存dump成bitmap或者压缩成其他图片格式.

在ubuntu下使用命令截屏:

Android G1手机的色深是16bit, 即R/G/B=5/6/6. 故需要一些特殊处理才能获得其屏幕图像。我们可以adb登录进入Android手机,先dump出/dev/fb0的内容,然后将dump出的文件拷贝到PC(ubuntu)上用convert命令进行处理。 1. 在Android手机上获取framebuffer内容: # cat /dev/graphics/fb0 > /mnt/sdcard/fb0 2. 把文件拷贝到PC上的/tmp目录: $ adb pull /mnt/sdcard/fb0 /tmp/fb0 3. 从/tmp/fb0文件中取出第一屏的内容(一般会有2到3屏的内容): $ dd bs=307200 count=1 if=/tmp/fb0 of=/tmp/screenshot1.xmp 这里,手机屏幕分辨率是320*480; 颜色深度为16bit (R/G/B=5/6/5),即2字节; 故有 320*480*2=307200 或在shell下执行: $ echo $((320*480*2)) 这里得到的图像是pixmap格式的. 4. 这时取到的截屏数据要转成每个颜色值为8bit的raw图像数据: 原理如下: int main(int argc, char *argv[]) { unsigned short in; // 16bit unsigned char out[3]; // 8bit*3 while (read(0, &in, 2) == 2) { out[2] = (in & 0x1f) << 3; out[1] = ((in >> 5) & 0x3f) << 2; out[0] = ((in >> 11) & 0x1f) << 3; write(1, out, 3); } return 0; } 将以上代码编译成执行文件/tmp/565to88后,再执行: $ /tmp/565to888 /tmp/screenshot888.xmp 这将把颜色转化为24bit色深。 5.最后把24bit色深的图像转换成PNG格式: $ /usr/bin/convert -depth 8 -size 320×480 rgb:screenshot888.xmp screenshot.png 现在可以用以下命令查看截屏(screenshot.png文件)啦: $ /usr/bin/display screenshot.png


转自:http://www.howandroid.com/2011/07/02/960.html

分享到:
评论

相关推荐

    ADBD Insecure (Android 2.1+).zip

    ADBD Insecure (Android 2.1+).zip

    adbd.rar adbd.apk 改名使用

    2.0的adbd 资源 部分手机可以使用 我上传两个 adbd 大家可以选择使用

    adbd Insecure 2.0

    adbd Insecure(超级adbd)能让您在已经ROOT的设备上强制以ROOT模式运行adbd(注意,如果您运行的是第三方内核,则可能已经具备了这项功能)。如果您的设备上运行的是原生(设备制造商的)内核,那么adbd就会以...

    ADB源码(android / platform / system / core)

    adb源码官网:https://android.googlesource.com/platform/system/core/可在以上链接获取adb源码集成到项目中。若下载失败可以下载上面的附件。

    Android-start-boot-analyze-.rar_android_android bootloader_andro

    本文主要介绍Android系统的启动过程,以Androidinit进程之后部分为主,init之前部分同标准Linux内核启动完全相同。于Android启动过程复杂,涉及C、C++及java部分内容,本文以流程分析为主线旨在让大家在分析Android...

    adbd-Insecure.apk

    adbd-Insecure-v2.00.apk ,最新版本的adbd.......................................

    adbd root修改版本

    修改过的adbd的arm的(非amr64), 用来让adb 可以用root的权限启动,方便调试。

    超级adbd 破解adb限制

    用于破解adb的限制,可以用于adb备份整个系统!

    adbd-Insecure.apk.zip

    ,验证你的手机是否已经root了 adb shell su ...行命令后,$ 变为 # 即 表示root 成功 ...2,安装adbd-insecure.apk ...打开应用将Enable insecure adbd 和 enable at boot 勾选上,设置好之后重进键入:adb root即可

    adbd_Chainfireadbd

    超级adbd_ChainfireadbdInsecure, 在root机子中可设置adb shell一运行就是root用户

    交叉编译arm Linux环境下的android-tools-adb

    交叉编译arm Linux环境下的android-tools-adb工具,本资源包含了完整的Ubuntu1604平台下的android-tools-adb源码包,openssl源码包,zlib源码包。以及完整的编译说明和指导,按照说明操作,可以轻松生成arm平台下可...

    adbd arm64 root 修改版

    用于需要adbd root 权限启动的adbd 修改版本,从android 10 的system.img解压得到

    天猫精灵里面的ADBD可执行程序

    天猫精灵里面的ADBD可执行程序,具体的可以参见链接: https://blog.csdn.net/leekwen/article/details/79923187

    Android开启ADB网络调试方法

    开启ADB网络调试 # setprop service.adb.tcp.port ... 您可能感兴趣的文章:android设置adb自带screenrecord录屏命令Android 修改adb端口的方法Android中ADB命令用法大结局Android ADB超简单的安装教程(推荐)androi

    adbd-Insecure

    有些手机即使root了通过adb root命令也还是无法使adb一直获得root权限,安装adbd后,授予其root权限,并勾选里面的选项后,运行adb root,在手机重启之前,adb可以一直获取root权限。

    ADB,即 Android Debug Bridge,它是 Android 开发/测试人员不可替代的强大工具,也是 Android 设备玩家的好玩具。

    注: 有部分命令的支持情况可能与 Android 系统版本及定制 ROM 的实现有关。 Other languages: English Table of Contents •基本用法 ◦命令语法 ◦为命令指定目标设备 ◦启动/停止 ◦查看 adb 版本 ◦以 root ...

    安卓adb工具包

    内含安卓adb工具包,刷机大侠刷机成功必备的工具包

    adbd超级权限

    手机打包系统必备,mtk平台自制线刷系统的工具

    adbd_downcc.zip

    前者是用来安装软件,后者用来打开软件,后者的一个使用场景让我对他重视:公司定制Android系统,在调试屏幕的时候要看是否满屏验证驱动是否正常,比较麻烦的做法是要拿到Android开发者手里用eclipse或者其他ide安装...

    android adb

    adb,adbd工具

Global site tag (gtag.js) - Google Analytics