android 直播画面截屏,android surfaceView+Mediaplayer播放视屏 截图

@SuppressLint("NewApi")

public void saveMyBitmap(Bitmap mBitmap) throws IOException

{

if

(android.os.Environment.getExternalStorageState().equals(

android.os.Environment.MEDIA_MOUNTED)) {

String mScreenshotPath =

Environment.getExternalStorageDirectory()

+ "/droidnova";

String imagePath = mScreenshotPath + "/"

+ System.currentTimeMillis() + ".jpg";

File file = new File(imagePath);

Log.i(TAG, "path==" + imagePath);

FileOutputStream fos;

try {

Toast.makeText(getContext(), "截图成功",

Toast.LENGTH_SHORT).show();

fos = new FileOutputStream(file);

mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);

fos.close();

} catch (FileNotFoundException e) {

Log.e("Panel", "FileNotFoundException", e);

} catch (IOException e) {

Log.e("Panel", "IOEception", e);

}

} else {

String mScreenshotPath = "mnt/sdcard/picture/";

String imagePath = mScreenshotPath + "/"

+ System.currentTimeMillis() + ".jpg";

File file = new File(imagePath);

Log.i(TAG, "path==" + imagePath);

FileOutputStream fos;

try {

Toast.makeText(getContext(), "截图成功",

Toast.LENGTH_SHORT).show();

fos = new FileOutputStream(file);

mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);

fos.close();

} catch (FileNotFoundException e) {

Log.e("Panel", "FileNotFoundException", e);

} catch (IOException e) {

Log.e("Panel", "IOEception", e);

}

}

}

@SuppressLint("NewApi")

public Bitmap getVideoFrame(String path, MediaPlayer

mediaPlayer) {

Bitmap bitmap = null;

// 2.3api下可用

MediaMetadataRetriever retriever = new

MediaMetadataRetriever();

try {

retriever.setDataSource(path);// 资源路径

String timeString = retriever

.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); //

这一句是必须的

long time = Long.parseLong(timeString) * 1000; //

获取总长度,这一句也是必须的

//

mSeekBarProgress是一个显示当前播放进度的进度条,因为之前通过mSeekBarProgress.setMax(mMediaPlayer.getDuration());设置过了,所以

//

mSeekBarProgress.getMax()获取的时这个视频的总时间,而mSeekBarProgress.getProgress()是播放的当前进度

long currentPostion = time *

mVideoProgress.getProgress()

/ mVideoProgress.getMax(); // 通过这个计算出想截取的画面所在的时间

bitmap = retriever.getFrameAtTime(currentPostion);//

按当前播放位置选择帧

} catch (IllegalArgumentExceptionex) {

ex.printStackTrace();

} catch (RuntimeException ex) {

ex.printStackTrace();

} finally {

try {

retriever.release();

} catch (RuntimeException ex) {

ex.printStackTrace();

}

}

return bitmap;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值