本文基于android6.0。首先找到screencap在Android源码中的位置,若不清楚,可以通过在android目录下通过命令find . -namescreencap.cpp。本文直接给出路径/android/frameworks/base/cmds/screencap/screencap.cpp。入口函数为main,只要编译就可以直接使用。如果需要将数据传出来,需要利用socket,后面会更新,将当前屏幕信息实时传输到web端显示。(data->data(), data->size()是需求的数据和大小)。
screencap.cpp源码如下:
<pre name="code" class="cpp">/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <linux/fb.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <binder/ProcessState.h>
#include <gui/SurfaceComposerClient.h>
#include <gui/ISurfaceComposer.h>
#include <ui/DisplayInfo.h>
#include <ui/PixelFormat.h>
// TODO: Fix Skia.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include <SkImageEncoder.h>
#include <SkData.h>
#pragma GCC diagnostic pop
using namespace android;
static uint32_t DEFAULT_DISPLAY_ID = ISurfaceComposer::eDisplayIdMain;//eDisplayIdMain = 0
static void usage(const char* pname)
{
fprintf(stderr,
"usage: %s [-hp] [-d display-id] [FILENAME]\n"
" -h: this message\n"
" -
Android屏幕截图技术解析

最低0.47元/天 解锁文章
9万+

被折叠的 条评论
为什么被折叠?



