android - viewpager中使用getDrawingCache方法截图在某些机型(联想,魅族...)第二次返回的bitmap和第一次相同
天蓬老师
天蓬老师 2017-04-17 17:35:15
0
1
605
//截图并保存
    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;
    }
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

membalas semua(1)
PHPzhong

根据测试,重新对fragment中的photoview进行

mPhotoView.destroyDrawingCache();
mPhotoView.setDrawingCacheEnabled(false);
mPhotoView.setDrawingCacheEnabled(true);
mPhotoView.buildDrawingCache();

即可,原因不清楚,求解答?

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan