-
Notifications
You must be signed in to change notification settings - Fork 209
screenshot
Su, Jia edited this page Dec 22, 2016
·
3 revisions
从4.0.6开始,推流支持预览截屏功能,截屏接口为: http://ksvc.github.io/KSYStreamer_Android/docs/reference/com/ksyun/media/streamer/kit/KSYStreamer.html#requestScreenShot(com.ksyun.media.streamer.util.gles.GLRender.ScreenShotListener)
需要通过ScreenShotListener获得requestScreenShot返回的Bitmap图像,可以使用如下方法将bitmap保存到sdcard:
mStreamer.requestScreenShot(new GLRender.ScreenShotListener() {
@Override
public void onBitmapAvailable(Bitmap bitmap) {
BufferedOutputStream bos = null;
try {
Date date = new Date() ;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss") ;
final String filename = "/sdcard/screenshot"+ dateFormat.format(date) + ".jpg";
bos = new BufferedOutputStream(new FileOutputStream(filename));
if (bitmap != null) {
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bos);
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(CameraActivity.this, "保存截图到 "+ filename,
Toast.LENGTH_SHORT).show();
}
});
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if (bos != null) try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
});