Android下截屏 及 格式转换

http://wiseideal.iteye.com/blog/1250175


Android下截屏 及 格式转换

  (2011-02-17 11:41:43)
转载
标签:  

it

 
(根据王研科先生的探索)
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/screenshot1.xmp >/tmp/screenshot888.xmp
这将把颜色转化为24bit色深。

5.最后把24bit色深的图像转换成PNG格式:
   $ /usr/bin/convert -depth 8 -size 320x480 rgb:screenshot888.xmp  screenshot.png

现在可以用以下命令查看截屏(screenshot.png文件)啦:
  $ /usr/bin/display  screenshot.png



附: HTC HD7上查看截屏:
手机侧:
  # cat /dev/graphics/fb0 > /mnt/sdcard/fb0
PC侧:
$ dd bs=$((480*800*2)) count=2 if=/tmp/fb0 of=/tmp/screenshot1.xmp
$ /tmp/565to888 </tmp/screenshot1.xmp >/tmp/screenshot888.xmp
$ convert -depth 16 -size 480x800 /tmp/screenshot888.xmp /tmp/screenshot888.png
$ display /tmp/screenshot888.png

转载于:https://my.oschina.net/jingxia/blog/697604

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值