Android 银幕截屏,并将之生成视频文件

Android 屏幕截屏,并将之生成视频文件
近段时候有一个问题困扰着我,那就是在玩一个android游戏的时候如何将这个游戏中的一些好玩,好看,好听的action保存起来。于是乎首先在google上面输入 android screen capture 搜了一把。说的比较多,但是也无非就是以下三种方法:
1.使用系统 \android-sdk-windows\tools\lib\ddms.jar 来实现,这种实现过程类似将手机连接到电脑(安装了Android SDK,Usb 驱动) 但是这种方法鄙人没有亲自尝试过。

2.第二种,如果看过launcher源码的人都应该知道,使用以下方法可以实现截屏,但是那个状态条会是黑色,如何向去掉这个黑色状态条可以将之设置成全屏就OK。并且使用这个方法截屏必须是在UI主线程内,而且在截屏前要确保该View已经绘制出来了。具体代码如下:

private Bitmap getViewBitmap(View v) {

if (!v.isDrawingCacheEnabled()) {

Log.d("v.isDrawingCacheEnabled() == false");

return null;

}

v.clearFocus();

v.setPressed(false);

boolean willNotCache = v.willNotCacheDrawing();

v.setWillNotCacheDrawing(false);

// Reset the drawing cache background color to fully transparent

// for the duration of this operation

int color = v.getDrawingCacheBackgroundColor();

v.setDrawingCacheBackgroundColor(0);

if (color != 0) {

v.destroyDrawingCache();

}

v.buildDrawingCache();

Bitmap cacheBitmap = v.getDrawingCache();

if (cacheBitmap == null) {

Log.d("v.getDrawingCache() == null");

return null;

}

Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);

// Restore the view

v.destroyDrawingCache();

v.setWillNotCacheDrawing(willNotCache);

v.setDrawingCacheBackgroundColor(color);

return bitmap;

}

3.第三种,技术含量稍微高点,但是要有root权限,那就是在FrameBuffer中直接取数据,这种功能也是最强大。而且此法要求对Linux,和C++,JNI有一定了解的。

图片有了,那么就如何将图片转换成视频了,可喜的是 一种叫做MotionJPEG格式的视频可以处理这件事,至于具体如何实现,请Google去吧。

热烈欢迎转载,而且可以不用说明出处


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/cupidclb/archive/2010/08/26/5839808.aspx
1 楼 qiaoweishu 2010-10-18  
好资料,学习中,谢谢!
2 楼 sfshine 2011-10-07  
楼主说了思想.