android视频截图
16lz
2021-12-04
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)
更多相关文章
- Android(安卓)Telephony 分析[PART IV]
- java.lang.NullPointerException Attempt to invoke virtual met
- Android(安卓)后台线程调用前台线程的几种方法
- android生命周期研究
- android使用retrofit
- Android集成okhttp
- Android(安卓)调用Gmail发送邮件
- android
- Android布局优化:ViewStub标签实现延迟加载(源码解析原理)