Android截屏方法汇总
来源:互联网 发布:ubuntu修改ssh端口 编辑:程序博客网 时间:2024/06/04 18:45
1. >= ICE_CREAM_SANDWICH (14)
直接使用 "/system/bin/screencap -p " 需要root吗?
2. >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH (14) < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2 (18)
android.view.Surface -> screenshot()
3. >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2 (18)
android.view.SurfaceControl -> screenshot()
4. JNI 调用 surfaceflinger/ISurfaceComposer.h captureScreen() 获取 framebuffer
参考 http://blog.csdn.net/zmyde2010/article/details/6925498
-------------------------------------------------------------------------------------------------------------------------------------
截取当前页面的屏:
public class ScreenShot {
// 获取指定Activity的截屏,保存到png文件
private static Bitmap takeScreenShot(Activity activity) {
// View是你需要截图的View
View view = activity.getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap b1 = view.getDrawingCache();
// 获取状态栏高度
Rect frame = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top;
Log.i("TAG", "" + statusBarHeight);
// 获取屏幕长和高
int width = activity.getWindowManager().getDefaultDisplay().getWidth();
int height = activity.getWindowManager().getDefaultDisplay()
.getHeight();
// 去掉标题栏
// Bitmap b = Bitmap.createBitmap(b1, 0, 25, 320, 455);
Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height
- statusBarHeight);
view.destroyDrawingCache();
return b;
}
// 保存到sdcard
private static void savePic(Bitmap b, String strFileName) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(strFileName);
if (null != fos) {
b.compress(Bitmap.CompressFormat.PNG, 90, fos);
fos.flush();
fos.close();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
- Android截屏方法汇总
- android 常用方法汇总
- android方法汇总
- Android数据存储方法汇总
- Android完全退出方法汇总
- Android Http请求方法汇总
- Android Http请求方法汇总
- Android Http请求方法汇总
- Android Http请求方法汇总
- android防破解方法汇总
- 【Android读写文件方法汇总】
- Android Http请求方法汇总
- Android Http请求方法汇总
- Android Http请求方法汇总
- Android Http请求方法汇总
- Android Http请求方法汇总
- Android Http请求方法汇总
- Android Http请求方法汇总
- 博主信息
- poj2010Moo University - Financial Aid
- 【CCF】数字排序
- 和芯星通科技(北京)有限公司
- 1054. The Dominant Color (20)
- Android截屏方法汇总
- hdu 3127 WHU girls 2009武汉网络赛 dp
- 监听所有rtp/rtcp包
- Apache Spark入门攻略
- Stanford机器学习---第一讲. Linear Regression with one variable
- Spring JTA multiple resource transactions in Tomcat with Atomikos example
- COCI试后心得
- LeetCode || Single Number III
- Windows下搭建IOS开发环境(一)