//截图并保存
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
Based on the test, re-do the photoview in the fragment
mPhotoView.destroyDrawingCache();
mPhotoView.setDrawingCacheEnabled(false);
mPhotoView.setDrawingCacheEnabled(true);
mPhotoView.buildDrawingCache();
is enough, the reason is not clear, please give me an answer?