Android implementation screenshot

Source: Internet
Author: User

Recently, the company's project requires that you be able to take a screenshot of the android screen and search for it online. I found a lot of examples, but not a lot of examples can be used. Then I found that the android system has its own commands.


Screencap and screenshot


Shell @ android:/$ screenshot-h

Screenshot-h

Unknown option -- husage: screenshot [-s soundfile] filename.png

-S: play a sound effect to signal success

-I: autoincrement to avoid overwriting filename.png

1 | shell @ android:/$ screencap-h

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.


Now that we have this command and the android source code, let's see how it is implemented.


We strongly recommend a website for code search.


Http://code.metager.de/source/xref/android/


Enter the name of the file you want to search for to find the desired file.


The result URL is in

Http://code.metager.de/source/xref/android/4.0.3/frameworks-base/cmds/screencap/screencap.cpp


This website finds that the code written in c ++ depends on a lot of library files, and it is not very nice to understand, so I did not look at it carefully, and then I searched it again.

Http://code.metager.de/source/xref/android/4.0.3/frameworks-base/cmds/screenshot/screenshot.c


After searching this file, we found that it was a simple screenshot tool with the main function.

Copy it and port it. Then

During the porting process, you need to add a libpng library file, but this is not difficult. Find the libpng library file from the android source code and configure the makefile file.


However, during the migration and development process, one difficulty is that the original fb0 data from some mobile phones is in the BGRA format and needs to be converted to the RGBA format, however, some mobile phones do not need to be converted directly in the RGBA format, but no difference is found yet. However, I believe it will not be too difficult to leave it to my colleagues who are working on upper-layer applications.


I wrote a demo by myself. If you need a friend, please download it at the following link.


Http://down.51cto.com/data/951556


Http://down.51cto.com/data/956437

The address below is used to implement two call Methods: jni and command line.





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.