TextureView截屏
public void getBitmap(TextureView vv)
{
String mPath = Environment.getExternalStorageDirectory().toString()
+ "/Pictures/" + Utilities.getDayTimeString() + ".png";
Toast.makeText(getApplicationContext(), "Capturing Screenshot: " + mPath, Toast.LENGTH_SHORT).show();
Bitmap bm = vv.getBitmap(); if(bm == null)
Log.e(TAG,"bitmap is null");
OutputStream fout = null;
File imageFile = new File(mPath); try {
fout = new FileOutputStream(imageFile);
bm.compress(Bitmap.CompressFormat.PNG, 90, fout);
fout.flush();
fout.close();
} catch (FileNotFoundException e) {
Log.e(TAG, "FileNotFoundException");
e.printStackTrace();
} catch (IOException e) {
Log.e(TAG, "IOException");
e.printStackTrace();
}
}
surfaceView截屏
private void screenShotVideo(String filePath) {
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource(filePath);
if (new File(filePath).exists()) {
if (Build.VERSION.SDK_INT >= 14) {
mmr.setDataSource(filePath, new HashMap<String, String>());
} else {
mmr.setDataSource(filePath);
}
//获取第一帧 (手机上还可以,tv盒子上很糊,保存在本地,adb pull出来,图片的清晰度和视频一样。不知为何很模糊)
Bitmap fristFrame = mmr.getFrameAtTime(0, MediaMetadataRetriever.OPTION_CLOSEST_SYNC);
mmr.release();
if (fristFrame != null) {
mImageView.setImageBitmap(fristFrame); mImageView.animate().alpha(1.0f).setDuration(60).start();
}
}
}
root 截图
Process process = null;
try{
process = Runtime.getRuntime().exec("su");
PrintStream outputStream = null;
try {
outputStream = new PrintStream(new BufferedOutputStream(process.getOutputStream(), 8192));
outputStream.println("screencap -p " + filePath);
outputStream.flush();
}catch(Exception e){
Log.e(TAG, e);
} finally {
if (outputStream != null) {
outputStream.close();
}
}
process.waitFor();
}catch(Exception e){
Log.e(TAG, e);
}finally {
if(process != null){
process.destroy();
}
}
网友评论