android视频截图
16lz
2021-01-23
import java.io.File;
import java.io.FileOutputStream;
import android.graphics.Bitmap;
import android.os.Environment;
import android.view.View;
public class TakeScreenShot {
public static String baseDIR= Environment.getExternalStorageDirectory
().getAbsolutePath();
public static String subDIR= "/wan";
public static String SCREEN_SHOTS_LOCATION= baseDIR+subDIR;
public static void takeScreenShot(View view) throws Exception {
takeScreenShot(view, "default");
}
public static void takeScreenShot(View view, String name) throws Exception {
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap b = view.getDrawingCache();
FileOutputStream fos = null;
try {
File sddir = new File(SCREEN_SHOTS_LOCATION);
if (!sddir.exists()) {
sddir.mkdirs();
}
// fos = new FileOutputStream(SCREEN_SHOTS_LOCATION+name+"_" +
System.currentTimeMillis() + ".jpg");
fos = new FileOutputStream(SCREEN_SHOTS_LOCATION+name + ".jpg");
if (fos != null) {
b.compress(Bitmap.CompressFormat.JPEG, 90, fos);
fos.close();
}
} catch (Exception e) {
}
}
}
调用:TakeScreenShot.takeScreenShot(solo.getViews().get(0),"WAN22");
takeScreenShot(View view)
import java.io.FileOutputStream;
import android.graphics.Bitmap;
import android.os.Environment;
import android.view.View;
public class TakeScreenShot {
public static String baseDIR= Environment.getExternalStorageDirectory
().getAbsolutePath();
public static String subDIR= "/wan";
public static String SCREEN_SHOTS_LOCATION= baseDIR+subDIR;
public static void takeScreenShot(View view) throws Exception {
takeScreenShot(view, "default");
}
public static void takeScreenShot(View view, String name) throws Exception {
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap b = view.getDrawingCache();
FileOutputStream fos = null;
try {
File sddir = new File(SCREEN_SHOTS_LOCATION);
if (!sddir.exists()) {
sddir.mkdirs();
}
// fos = new FileOutputStream(SCREEN_SHOTS_LOCATION+name+"_" +
System.currentTimeMillis() + ".jpg");
fos = new FileOutputStream(SCREEN_SHOTS_LOCATION+name + ".jpg");
if (fos != null) {
b.compress(Bitmap.CompressFormat.JPEG, 90, fos);
fos.close();
}
} catch (Exception e) {
}
}
}
调用:TakeScreenShot.takeScreenShot(solo.getViews().get(0),"WAN22");
takeScreenShot(View view)
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer