@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;
}