android – “adb screencap /sdcard/screenshot.raw”生成什么格式? (没有“-p”标志)

我希望使用没有-p标志的adb screencap实用程序.我想象输出将以原始格式转储,但看起来不像.我尝试使用Pillow( python)库打开原始图像文件导致:
$adb pull /sdcard/screenshot.raw screenshot.raw
$python
>>> from PIL import Image
>>> Image.open('screenshot.raw')
Traceback (most recent call last):
  File "<stdin>",line 1,in <module>
  File "/Users/....../lib/python2.7/site-packages/PIL/Image.py",line 2025,in open
    raise IOError("cannot identify image file")
IOError: cannot identify image file

找不到像这样阅读原始图像的正确方法,我甚至给了以下镜头:How to read a raw image using PIL?

>>> with open('screenshot.raw','rb') as f:
...     d = f.read()
... 
>>> from PIL import Image
>>> Image.frombuffer('RGB',len(d),d)
__main__:1: RuntimeWarning: the frombuffer defaults may change in a future release; for portability,change the call to read:
  frombuffer(mode,size,data,'raw',mode,1)
Traceback (most recent call last):
  File "<stdin>",in <module>
  File "/Users/..../lib/python2.7/site-packages/PIL/Image.py",line 1896,in frombuffer
    return frombytes(mode,decoder_name,args)
  File "/Users/..../lib/python2.7/site-packages/PIL/Image.py",line 1821,in frombytes
    im = new(mode,size)
  File "/Users/..../lib/python2.7/site-packages/PIL/Image.py",line 1787,in new
    return Image()._new(core.fill(mode,color))
TypeError: must be 2-item sequence,not int

所有可能的模式选项都会导致相同的TypeError异常.

这是hexdump实用程序揭示的内容

$hexdump -C img.raw | head
00000000  d0 02 00 00 00 05 00 00  01 00 00 00 1e 1e 1e ff  |................|
00000010  1e 1e 1e ff 1e 1e 1e ff  1e 1e 1e ff 1e 1e 1e ff  |................|
*
000038c0  1e 1e 1e ff 1e 1e 1e ff  21 21 21 ff 2b 2b 2b ff  |........!!!.+++.|
000038d0  1e 1e 1e ff 1e 1e 1e ff  1e 1e 1e ff 1e 1e 1e ff  |................|
*
00004400  1e 1e 1e ff 1e 1e 1e ff  47 47 47 ff 65 65 65 ff  |........GGG.eee.|
00004410  20 20 20 ff 1e 1e 1e ff  1e 1e 1e ff 1e 1e 1e ff  |   .............|
00004420  1e 1e 1e ff 1e 1e 1e ff  1e 1e 1e ff 1e 1e 1e ff  |................|
*

在osx上:

$file screenshot.raw 
screenshot.raw: data

screencap帮助页面没有显示关于没有-p标志的输出数据的格式:

$adb shell screencap -h
usage: screencap [-hp] [FILENAME]
   -h: this message
   -p: save the file as a png.
If FILENAME ends with .png it will be saved as a png.
If FILENAME is not given,the results will be printed to stdout.

解决方法

感谢您的文件摘录,我猜您的原始文件格式为
width x height然后整个RGBA像素集(32位)(宽x高高倍)
在这里,我看到你拍摄了720×1280的图像..

可以使用ImageMagick工具集来帮助您以更合适的文件格式查看/转换它.
以下是可能对您有所帮助的示例
(ImageMagick转换命令,osx见http://cactuslab.com/imagemagick/)

# skip header info  
dd if=screenshot.raw of=screenshot.rgba skip=12 bs=1
# convert rgba to png
convert -size 720x1280 -depth 8 screenshot.rgba screenshot.png

如果它不起作用,您可以尝试通过skip = 8和/或720×1280 by 1280×720更改skip = 12 ..

希望有所帮助

相关文章

这篇“android轻量级无侵入式管理数据库自动升级组件怎么实现...
今天小编给大家分享一下Android实现自定义圆形进度条的常用方...
这篇文章主要讲解了“Android如何解决字符对齐问题”,文中的...
这篇文章主要介绍“Android岛屿数量算法怎么使用”的相关知识...
本篇内容主要讲解“Android如何开发MQTT协议的模型及通信”,...
本文小编为大家详细介绍“Android数据压缩的方法是什么”,内...