“adb screencap /sdcard/截图”是什么格式?原始”呢?(没有“p”标记)

时间:2023-01-04 00:24:52

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 screencap实用工具,而不使用-p标志。我想象输出将以原始格式转储,但看起来不像。我尝试用枕头(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

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?

找到了不适合阅读这样的原始图片的方法,我甚至给了下面的一个镜头:如何使用PIL来读取raw图像?

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

All possible mode option lead to same TypeError exception.

所有可能的模式选项导致相同的类型错误异常。

Here is what hexdump utility reveals:

以下是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  |................|
*

On osx:

在osx上:

$ file screenshot.raw 
screenshot.raw: data

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

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.

2 个解决方案

#1


3  

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

由于您的文件的提取,我猜测您的原始文件被格式化为宽度x高度,然后是整个RGBA像素(32位)(宽度x高度),这里我看到您获得了一个720x1280图像。

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/ )

请使用ImageMagick工具集帮助您以更适当的文件格式查看/转换它。下面的示例可以帮助您(ImageMagick convert命令,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

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

如果它不工作,您可以尝试更改skip=12,跳过=8和/或720x1280 * 1280x720。

Hope that help

希望帮助

#2


7  

Format:

格式:

  • 4 bytes as uint32 - width
  • 4字节为uint32 -宽度。
  • 4 bytes as uint32 - height
  • 4字节为uint32 - height。
  • 4 bytes as uint32 - pixel format
  • 4字节为uint32 -像素格式。
  • (width * heigth * bytespp) bytes as byte array - image data, where bytespp is bytes per pixels and depend on pixel format. Usually bytespp is 4.
  • (宽度* heigth * bytespp)字节作为字节数组-图像数据,其中bytespp是字节/像素,依赖于像素格式。通常bytespp是4。

Info from source code of screencap.

信息来自于屏幕截图的源代码。

For your example:

你的例子:

00000000  d0 02 00 00 00 05 00 00  01 00 00 00 1e 1e 1e ff
  • d0 02 00 00 - width - uint32 0x000002d0 = 720
  • d0 02 00 - width - uint32 0x000002d0 = 720。
  • 00 05 00 00 - height - uint32 0x00000500 = 1280
  • 000500 -高度- uint32 0x00000500 = 1280。
  • 01 00 00 00 - pixel format - uint32 0x00000001 = 1 = PixelFormat.RGBA_8888 => bytespp = 4 => RGBA
  • 01元-像素格式- uint32 0x00000001 = 1像素格式。RGBA_8888 => bytespp = 4 => RGBA。
  • 1e 1e 1e ff - first pixel data - R = 0x1e; G = 0x1e; B = 0x1e; A = 0xff;
  • 1e 1e1e ff - first pixel data - R = 0x1e;G = 0 x1e;B = 0 x1e;一个= 0 xff;

Pixels with data stored in array of bytes with size 720*1280*4.

数据存储在字节数组中的像素,大小为720*1280*4。

#1


3  

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

由于您的文件的提取,我猜测您的原始文件被格式化为宽度x高度,然后是整个RGBA像素(32位)(宽度x高度),这里我看到您获得了一个720x1280图像。

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/ )

请使用ImageMagick工具集帮助您以更适当的文件格式查看/转换它。下面的示例可以帮助您(ImageMagick convert命令,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

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

如果它不工作,您可以尝试更改skip=12,跳过=8和/或720x1280 * 1280x720。

Hope that help

希望帮助

#2


7  

Format:

格式:

  • 4 bytes as uint32 - width
  • 4字节为uint32 -宽度。
  • 4 bytes as uint32 - height
  • 4字节为uint32 - height。
  • 4 bytes as uint32 - pixel format
  • 4字节为uint32 -像素格式。
  • (width * heigth * bytespp) bytes as byte array - image data, where bytespp is bytes per pixels and depend on pixel format. Usually bytespp is 4.
  • (宽度* heigth * bytespp)字节作为字节数组-图像数据,其中bytespp是字节/像素,依赖于像素格式。通常bytespp是4。

Info from source code of screencap.

信息来自于屏幕截图的源代码。

For your example:

你的例子:

00000000  d0 02 00 00 00 05 00 00  01 00 00 00 1e 1e 1e ff
  • d0 02 00 00 - width - uint32 0x000002d0 = 720
  • d0 02 00 - width - uint32 0x000002d0 = 720。
  • 00 05 00 00 - height - uint32 0x00000500 = 1280
  • 000500 -高度- uint32 0x00000500 = 1280。
  • 01 00 00 00 - pixel format - uint32 0x00000001 = 1 = PixelFormat.RGBA_8888 => bytespp = 4 => RGBA
  • 01元-像素格式- uint32 0x00000001 = 1像素格式。RGBA_8888 => bytespp = 4 => RGBA。
  • 1e 1e 1e ff - first pixel data - R = 0x1e; G = 0x1e; B = 0x1e; A = 0xff;
  • 1e 1e1e ff - first pixel data - R = 0x1e;G = 0 x1e;B = 0 x1e;一个= 0 xff;

Pixels with data stored in array of bytes with size 720*1280*4.

数据存储在字节数组中的像素,大小为720*1280*4。