Capture screen in gingerbread (screenshot capture for Android 2.3)

Source: Internet
Author: User
Tags getbase

This article uses the zmyde2010 method to start the screenshot service on sunsumg i9100 and record the operation process here.

Link to zmyde2010: http://blog.csdn.net/zmyde2010/article/details/6925498

This screenshot method is based on the android source code.

Frameworks \ base \ Services \ surfaceflinger \ tests \ screencap. cpp

 

1 /*
2 x copyright (c) 2010 the android open source project
3 *
4 * licensed under the Apache license, version 2.0 (the "License ");
5 * you may not use this file except T in compliance with the license.
6 * You may obtain a copy of the license
7 *
Http://www.apache.org/licenses/LICENSE-2.0 8 *
9 *
10 * unless required by applicable law or agreed to in writing, software
11 * distributed under the license is distributed on an "as is" basis,
12 * Without warranties or conditions of any kind, either express or implied.
13 * See the license for the specific language governing permissions and
14 * limitations under the license.
15 */
16
17 # include <utils/log. h>
18
19 # include <binder/ipcthreadstate. h>
20 # include <binder/processstate. h>
21 # include <binder/iservicemanager. h>
22
23 # include <binder/imemory. h>
24 # include <surfaceflinger/isurfacecomposer. h>
25
26 # include <skimageencoder. h>
27 # include <skbitmap. h>
28
29 using namespace android;
30
31 int main (INT argc, char ** argv)
32 {
33 If (argc! = 2 ){
34 printf ("Usage: % s path \ n", argv [0]);
35 exit (0 );
36}
37
38 const string16 name ("surfaceflinger ");
39 sp <isurfacecomposer> composer;
40 getservice (name, & composer );
41
42 sp <imemoryheap> heap;
43 uint32_t W, h;
44 pixelformat F;
45 status_t err = composer-> capturescreen (0, & heap, & W, & H, & F, 0, 0 );
46 If (Err! = No_error ){
47 fprintf (stderr, "screen capture failed: % s \ n", strerror (-err ));
48 exit (0 );
49}
50
51 printf ("screen capture success: W = % u, H = % u, pixels = % P \ n ",
52 W, H, heap-> getbase ());
53
54 printf ("Saving file as PNG in % s... \ n", argv [1]);
55
56 skbitmap B;
57 B. setconfig (skbitmap: kargb_8888_config, W, H );
58 B. setpixels (heap-> getbase ());
59 skimageencoder: encodefile (argv [1], B,
60 skimageencoder: kpng_type, skimageencoder: kdefaultquality );
61
62 Return 0;
63}

Download the Code provided in this article. The method I use is to add the code to the CM source code.

Compile

To maintain source code consistency, place the screencap code in the packages/apps directory.

The next step is to compile the system so that the new system package contains the screencap program.

To include the program we added when compiling the target source code, add the package name in the bulid/target/product/generic. mk file:

Product_packages: =/
Accountandsyncset.pdf/
Carhome/
Deskclock/
......
Syncprovider/
Screencap

 

Then, in Android. mk, note that the local_module_tags: = optional statement is included.

After completing these steps, you can compile the source code to burn the system.

After the system is burned, in the system, the default property of the screenshot program is to start automatically at startup, as a system service waiting for calling.

In your own application, use the following statement to enable the Service:

Sendbroadcast (new intent ("com. Android. capture_screen "));

Generate an image under the SD card directory.

In this way, Wayne successfully runs the screenshot program on the i9100 mobile phone. The same is true. please correct me!

 

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.