Capture Screen in Gingerbread(Android 2.3实现截屏)
2012-01-03 22:46
471 查看
本文是采用zmyde2010的方法,在sunsumg i9100上启动截屏服务,在此记录操作过程。
zmyde2010文章的链接:/article/1887556.html
此截屏方法是参照Android源码
frameworks\base\services\surfaceflinger\tests\screencap\screencap.cpp
1 /*
2 * 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 in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0 9 *
* 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 <utils/Log.h>
#include <binder/IPCThreadState.h>
#include <binder/ProcessState.h>
#include <binder/IServiceManager.h>
#include <binder/IMemory.h>
#include <surfaceflinger/ISurfaceComposer.h>
#include <SkImageEncoder.h>
#include <SkBitmap.h>
using namespace android;
int main(int argc, char** argv)
{
if (argc != 2) {
printf("usage: %s path\n", argv[0]);
exit(0);
}
const String16 name("SurfaceFlinger");
sp<ISurfaceComposer> composer;
getService(name, &composer);
sp<IMemoryHeap> heap;
uint32_t w, h;
PixelFormat f;
status_t err = composer->captureScreen(0, &heap, &w, &h, &f, 0, 0);
if (err != NO_ERROR) {
fprintf(stderr, "screen capture failed: %s\n", strerror(-err));
exit(0);
}
printf("screen capture success: w=%u, h=%u, pixels=%p\n",
w, h, heap->getBase());
printf("saving file as PNG in %s ...\n", argv[1]);
SkBitmap b;
b.setConfig(SkBitmap::kARGB_8888_Config, w, h);
b.setPixels(heap->getBase());
SkImageEncoder::EncodeFile(argv[1], b,
SkImageEncoder::kPNG_Type, SkImageEncoder::kDefaultQuality);
return 0;
}下载该文中的提供的代码,我所采用的方法是将代码加入到了CM的源码中。
编译
为保持源码的一致性,将screencap代码放在packages/apps目录下。
接下来就是编译系统,使新生成的系统包内含screencap程序。
要使目标源码编译时包含我们添加进去的程序,需要在bulid/target/product/generic.mk文件中将package name添加进去:
PRODUCT_PACKAGES := /
AccountAndSyncSettings /
CarHome /
DeskClock /
……
SyncProvider /
Screencap
然后在Android.mk中注意包含LOCAL_MODULE_TAGS := optional 语句。
完成这些步骤之后,就可以开始编译源码烧写系统了。
烧好系统后, 在系统中,截屏程序默认属性为开机自启动,作为系统服务等待调用。
在自己的应用程序中,使用如下语句启用服务
sendBroadcast(new Intent("com.android.CAPTURE_SCREEN"));在sd卡目录下生成图片。
这样,wayne将截屏程序在i9100手机中就运行成功了,还是一样,欢迎指正!
zmyde2010文章的链接:/article/1887556.html
此截屏方法是参照Android源码
frameworks\base\services\surfaceflinger\tests\screencap\screencap.cpp
1 /*
2 * 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 in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0 9 *
* 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 <utils/Log.h>
#include <binder/IPCThreadState.h>
#include <binder/ProcessState.h>
#include <binder/IServiceManager.h>
#include <binder/IMemory.h>
#include <surfaceflinger/ISurfaceComposer.h>
#include <SkImageEncoder.h>
#include <SkBitmap.h>
using namespace android;
int main(int argc, char** argv)
{
if (argc != 2) {
printf("usage: %s path\n", argv[0]);
exit(0);
}
const String16 name("SurfaceFlinger");
sp<ISurfaceComposer> composer;
getService(name, &composer);
sp<IMemoryHeap> heap;
uint32_t w, h;
PixelFormat f;
status_t err = composer->captureScreen(0, &heap, &w, &h, &f, 0, 0);
if (err != NO_ERROR) {
fprintf(stderr, "screen capture failed: %s\n", strerror(-err));
exit(0);
}
printf("screen capture success: w=%u, h=%u, pixels=%p\n",
w, h, heap->getBase());
printf("saving file as PNG in %s ...\n", argv[1]);
SkBitmap b;
b.setConfig(SkBitmap::kARGB_8888_Config, w, h);
b.setPixels(heap->getBase());
SkImageEncoder::EncodeFile(argv[1], b,
SkImageEncoder::kPNG_Type, SkImageEncoder::kDefaultQuality);
return 0;
}下载该文中的提供的代码,我所采用的方法是将代码加入到了CM的源码中。
编译
为保持源码的一致性,将screencap代码放在packages/apps目录下。
接下来就是编译系统,使新生成的系统包内含screencap程序。
要使目标源码编译时包含我们添加进去的程序,需要在bulid/target/product/generic.mk文件中将package name添加进去:
PRODUCT_PACKAGES := /
AccountAndSyncSettings /
CarHome /
DeskClock /
……
SyncProvider /
Screencap
然后在Android.mk中注意包含LOCAL_MODULE_TAGS := optional 语句。
完成这些步骤之后,就可以开始编译源码烧写系统了。
烧好系统后, 在系统中,截屏程序默认属性为开机自启动,作为系统服务等待调用。
在自己的应用程序中,使用如下语句启用服务
sendBroadcast(new Intent("com.android.CAPTURE_SCREEN"));在sd卡目录下生成图片。
这样,wayne将截屏程序在i9100手机中就运行成功了,还是一样,欢迎指正!
相关文章推荐
- Android: How to Capture Screen in Gingerbread(2.3中实现截屏)
- Android: How to Capture Screen in Gingerbread(2.3中实现截屏) .
- Android: How to Capture Screen in Gingerbread(2.3中实现截屏)
- Android: How to Capture Screen in Gingerbread(2.3中实现截屏)
- Android: (2.3中实现截屏How to Capture Screen in Gingerbread)
- Android: How to Capture Screen in Gingerbread(2.3中实现截屏)(续)
- Android: How to Capture Screen in Gingerbread(2.3中实现截屏)(续)
- 编译Android 2.3 Gingerbread Source
- Appium - Capture Screenshot On Failure Or Pass In Android Test Automation
- How to capture screen to bitmap如何实现截屏(Symbian)
- Android 2.3 GingerBread for VirtualBox x86编译指南
- Android 2.3 GingerBread for VirtualBox x86编译指南
- Android screen capture in Eclipse DDMS
- android 4.3 操作源码实现系统截屏(暂无移植性)
- Android实现的截屏小程序示例
- Android: 如何实现 in_app purchase
- Android gingerbread eMMC booting
- 【转】在android平台上实现基于xmpp的摄像头截屏发送
- 手动安装Chrome截屏控件扩展-Xproer.ScreenCapture(ScreenCapture.crx)
- Android2.3 SDK以上编译出现Multiple substitutions specified in non-positional format的分析