[Android] screenshot capture and format conversion in the android Simulator

Source: Internet
Author: User

1. simulator Information

The color depth of the android simulator is 16 bits, that is, R/G/B = 5/6/5. Therefore, some special processing is required to obtain the screen image.

We can log on to the android simulator using ADB. First, dump the/dev/fb0 content, and then copy the dump file to PC (UBUNTU) and run the convert command to process it.

 

Obtain the framebuffer information of the simulator through a program

The mem is 614400
The line_length is: 640
The xres is: 320
The yres is: 480
Bits_per_pixel is: 16

2. screenshot capture and conversion process

1) obtain the framebuffer content on the Android phone:

# Cat/dev/graphics/fb0>/mnt/sdcard/fb0

2) copy the file to the/tmp directory on the PC:

$ ADB pull/mnt/sdcard/fb0/tmp/fb0


3) extract the content of the first screen from the/tmp/fb0 file (usually 2 to 3 screens ):

$ Dd BS = 307200 COUNT = 1 If =/tmp/fb0 of =/tmp/screenshot1.xmp

Cause: the screen resolution of the mobile phone is 320*480; the color depth is 16 bit (R/G/B = 5/6/5), that is, 2 bytes;
320x480*2 = 307200
Or run the following command in shell:

$ Echo $(320*480*2 ))

The image obtained here is in pixmap format.

Dd command: Use a block of the specified size to copy an object and perform the specified conversion at the same time.

If = file // input file name. The default value is standard input.
Of = file // output file name. The default value is standard output.
IBS = bytes // read bytes at a time (that is, the size of a block is bytes ).
Obs = bytes // write bytes at a time (that is, the size of a block is bytes ).
BS = bytes // set the size of the read/write block to bytes at the same time, which can replace IBS and obs.
CBS = bytes // One-time conversion of bytes, that is, the size of the conversion buffer.
Skip = blocks // you can skip blocks from the beginning of the input file before copying them.
Seek = blocks // skip blocks from the beginning of the output file and then start copying. (Usually only valid when the output file is a disk or tape)
Count = blocks // copy only blocks. The block size is equal to the number of bytes specified by IBS.


4) at this time, the screenshot data will be converted into raw image data with an 8-bit color value:

The principle is as follows:

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;         //5 shift 3 = 8        out[1] = ((in >> 5) & 0x3f) << 2;  //6 shift 2 = 8        out[0] = ((in >> 11) & 0x1f) << 3; //5 shift 3 = 8        write(1, out, 3);    }    return 0;}

Compile the above Code into the execution file/tmp/565to88 and then execute:

$/Tmp/565to888 </tmp/screenshot1.xmp>/tmp/screenshot888.xmp

This will convert the color into a 24-bit color depth.


5) Finally, convert the 24-bit deep-color image to PNG format:

$/Usr/bin/convert-depth 8-size 320x480 RGB: screenshot888.xmp
Screenshot.png


6. Now you can use the following command to upload the screenshot (screenshot.png file:

$/Usr/bin/display screenshot.png

Attachment: View screenshots on HTC hd7:
Mobile phone side:
# Cat/dev/graphics/fb0>/mnt/sdcard/fb0
PC side:

$ 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.