Heim > Fragen und Antworten > Hauptteil
//截图并保存
private String screenshotAndSave() {
// Bitmap bitmap = ScreenShotUtils.getScreenshot(this);
// mViewPager.setDrawingCacheEnabled(true);
// mViewPager.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
// View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
// mViewPager.layout(0, 0, mViewPager.getMeasuredWidth(), mViewPager.getMeasuredHeight());
// mViewPager.buildDrawingCache(true);
Bitmap bitmap = getScreenViewBitmap(mViewPager);
String fileName = cacheName + "_" + mViewPager.getCurrentItem() +
ImageUtils.JPG_SUFFIX;
ImageUtils.saveBitmap(bitmap, isCreateMode ? 30 : 100, ConstantValues.SCREENSHOT_PATH,
fileName);
// mViewPager.setDrawingCacheEnabled(false);
return fileName;
}
private Bitmap getScreenViewBitmap(View v) {
v.setDrawingCacheEnabled(true);
v.buildDrawingCache(true);
//creates immutable clone
Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
v.setDrawingCacheEnabled(false); //clear drawing cache
return b;
}
PHPz2017-04-17 17:37:15
根据测试,重新对fragment中的photoview进行
mPhotoView.destroyDrawingCache();
mPhotoView.setDrawingCacheEnabled(false);
mPhotoView.setDrawingCacheEnabled(true);
mPhotoView.buildDrawingCache();
即可,原因不清楚,求解答?