ScreenShot 截图工具类
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.view.View; import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException; /**
* view截图实现
*/
public class ScreenShot {
private static final String TAG = ScreenShot.class.getSimpleName(); // 获取指定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;
// int statusBarHeight = frame.height() - view.getHeight(); //获取屏幕长和高
int width = activity.getWindowManager().getDefaultDisplay().getWidth();
int height = activity.getWindowManager().getDefaultDisplay().getHeight(); Logger.d(TAG, "Rect height:" + frame.height() + " Rect width: " + frame.width());
Logger.d(TAG, "view height:" + view.getHeight() + " view width: " + view.getWidth());
Logger.d(TAG, "screen_shot:" + (width - 40) + " " + statusBarHeight + " " + 40 + " " + (height - statusBarHeight)); //去掉标题栏
//Bitmap b = Bitmap.createBitmap(b1, 0, 25, 320, 455);
// Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height - statusBarHeight); //全屏
Bitmap b = Bitmap.createBitmap(b1, width - 40, statusBarHeight * 2, 40, height - statusBarHeight * 2); //全屏
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();
}
} //程序入口
public static String shoot(Activity a) {
ScreenShot.savePic(ScreenShot.takeScreenShot(a), "sdcard/maizuo_xx.png");
return "/maizuo_xx.png";
} }
ScreenShot 截图工具类的更多相关文章
- Android 开源控件与常用开发框架开发工具类
Android的加载动画AVLoadingIndicatorView 项目地址: https://github.com/81813780/AVLoadingIndicatorView 首先,在 bui ...
- google浏览器截图工具 Open Screenshot(代码截图)
有的时候特别想把自己写的代码保存为图片,但是代码的内容很长,用普通的截图工具只能一次一次的拼接起来,太麻烦了.这里使用了Google的截图插件,很好用. 或者使用360极速浏览器-->保存网页也 ...
- App开发流程之图像处理工具类
先罗列一下工具类中提供的方法: /** * 根据原始view和毛玻璃样式,获取模糊视图,并自动作为原view的subview(如果不需要作为子视图,自行调用removeFromSuperview) * ...
- JavaScript的My97Date日期工具类的使用
开发人员最喜欢的事情就是有工具然后拿来直接使用(. ~ .) 使用截图: 1.设置input标签 2.根据其DEMO文件,引入,进行事件处理 3.效果如图 4.效果如图 代码: <!DOCTYP ...
- 01_JavaMail_05_创建邮件工具类MailUtils等方便发送邮件
[工程截图] [代码实现] [Mail.java] package com.Higgin.Utils; import java.util.ArrayList; import java.util.Lis ...
- Java图片工具类,完成图片的截取和任意缩放
package com.common.util; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Renderin ...
- Ubuntu下的截图工具
转载自:http://os.yesky.com/88/8733088.shtml 相信大家对于屏幕截图(或称抓图)应该不会陌生,在Windows平台上,我们可以使用许多第三方的专业抓图软件如SnagI ...
- [C# 开发技巧]实现属于自己的截图工具
[C# 开发技巧]实现属于自己的截图工具 一.引言 之前一直都是写一些C#基础知识的内容的,然而有些初学者可能看完了这些基础知识之后,会有这样一个疑惑的——我了解了这些基础知识之后,我想做一些工具怎么 ...
- 第13天 JSTL标签、MVC设计模式、BeanUtils工具类
第13天 JSTL标签.MVC设计模式.BeanUtils工具类 目录 1. JSTL的核心标签库使用必须会使用 1 1.1. c:if标签 1 1.2. c:choos ...
随机推荐
- element 文件上传大小控制
1.页面代码 <el-upload :show-file-list="false" class="upload-demo" :before-upload= ...
- 【fiddler】Fiddller的应用
一.fiddler抓取移动端接口 1.获取PC端IP 2.手机ip设置为与电脑同一局域网ip并配置代理 1)手机ip地址与pc地址连接同一局域网网络 2)代理设置为手动,主机名为PCip,端口号为88 ...
- Delphi 方法指令字
- 安装python包时出现VC++ 错误的解决方案
方式一 就是按照提示在微软的官网上下载宇宙第一编辑器VS,安装完之后卸载掉就好了. 方式二 下载whl包安装 因为python有很多native的包,不是纯python代码,用了诸如c/c++的代码, ...
- golang结构体json格式化的时间格式
golang结构体json格式化的时间格式 在我们开发中,经常会解析time.Time 往往前台传过来的时候,是个string 但是我们希望在结构体转成time.Time type Param str ...
- 小A的数学题
小A最近开始研究数论题了,这一次他随手写出来一个式子, 但是他发现他并不太会计算这个式子,你可以告诉他这个结果吗,答案可能会比较大,请模上1000000007. 输入描述: 一行两个正整数n,m一行两 ...
- 操作mysql 中文乱码情况
解决方法 : 在连接字符串中设置charset=utf8 即可正常添加中文字符 <add name="mtgzghEntities" connectionString=& ...
- Waiting (TTFB) 时间
什么是 Waiting (TTFB) 时间 TTFB 是 Time to First Byte 的缩写,指的是浏览器开始收到服务器响应数据的时间(后台处理时间+重定向时间),是反映服务端响应速度的重要 ...
- [Luogu] 天天爱跑步
https://www.luogu.org/problemnew/show/P1600 https://www.zybuluo.com/wsndy-xx/note/1135243 乱写的暴力,这道题暴 ...
- Hdu 1247 Hat's Words(Trie树)
Hat's Words Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...