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

Source: Internet
Author: User

1. simulator information Android simulator mobile phone color depth is 16 bit, 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. The mem is: 614400The line_length is: 640The xres is: 320The yres is: 480bits_per_pixel is: 16 II. screenshot and conversion process 1) get 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 (normally there will be 2 to 3 screens ): $ dd bs = 307200 count = 1 if =/tmp/fb0 of =/tmp/screenshot1.xmp cause: the cell phone screen resolution is 320*480; color Depth: 16 bits (R/G/B = 5/6/5), that is, 2 words So there are 320*480*2 = 307200 www.2cto.com or execute 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 convert if = file // input the file name at the same time. 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 is converted into raw image data with 8 bits in each color value. The principle is as follows: [html] 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 converts the color to 24-bit color depth. 5) 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: $/usr/bin/display screenshot.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.