suchen

Heim  >  Fragen und Antworten  >  Hauptteil

android - viewpager中使用getDrawingCache方法截图在某些机型(联想,魅族...)第二次返回的bitmap和第一次相同

//截图并保存
    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;
    }
天蓬老师天蓬老师2772 Tage vor608

Antworte allen(1)Ich werde antworten

  • PHPz

    PHPz2017-04-17 17:37:15

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

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

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

    Antwort
    0
  • StornierenAntwort