"adb screencap/sdcard/screenshot.raw"采用什么格式?生产? (不带"-p"标志) [英] What format does "adb screencap /sdcard/screenshot.raw" produce? (without "-p" flag)

查看:107
本文介绍了"adb screencap/sdcard/screenshot.raw"采用什么格式?生产? (不带"-p"标志)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用不带-p标志的adb screencap实用程序.我以为输出将以原始格式转储,但看起来却不一样.我尝试使用Pillow(python)库打开原始图像文件的结果是:

I am looking to use adb screencap utility without the -p flag. I imagined output will be dumped in raw format, but doesn't look like it. My attempts of opening the raw image file with Pillow (python) library resulted in:

$ 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

发现这种读取原始图像的方法不正确,我什至给出了以下建议:

Found out not the right way to read raw images like this, I even gave the following a shot: 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, 0, 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/..../lib/python2.7/site-packages/PIL/Image.py", line 1896, in frombuffer
    return frombytes(mode, size, data, 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, size, color))
TypeError: must be 2-item sequence, not int

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

All possible mode option lead to same TypeError exception.

以下是hexdump实用工具显示的内容:

Here is what hexdump utility reveals:

$ 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标志的输出数据格式的信息:

screencap help page doesn't reveal much either about format of output data without -p flag:

$ 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.

推荐答案

感谢您提取文件,我猜您的原始文件格式为 宽度x高度,然后是整个RGBA像素集(32位)(宽度x高度乘以) 在这里,我看到您捕获了720x1280的图像.

Thanks to the extract of your file , I guess your raw file is formated as width x height then the whole set of RGBA pixels (32 bits) (width x height times) Here I see you get a 720x1280 image captured..

可以使用ImageMagick工具集来帮助您以更合适的文件格式查看/转换它. 在下面的示例中可能会为您提供帮助 (ImageMagick转换命令,关于osx,请参见 http://cactuslab.com/imagemagick/)

May the ImageMagick toolset help you to view/convert it in a more appropriate file format. Here below a sample that may help you (ImageMagick convert command, for osx see 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 = 12更改为skip = 8,和/或将720x1280更改为1280x720 ..

If it doesn't work you may try changing skip=12 by skip=8 and/or 720x1280 by 1280x720 ..

希望有帮助

这篇关于"adb screencap/sdcard/screenshot.raw"采用什么格式?生产? (不带"-p"标志)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆