在项目中需要做书的打开动画,但是需要做动画的view所在的页面 和动画的页面不在一个页面上,这就需要在动画的页面上“复制”一个和做动画视图一样的view了,但是该view不是一个imageview 无法直接拿到bitmap,但是可以通过缓存取到。(mCoverView是需要获取显示bitmap的view) mCoverView.setDrawingCacheEnabled(true); mCoverView.buildDrawingCache(); Bitmap createBitmap = Bitmap.createBitmap(mCoverView.getDrawingCache(true)); mAnimCover.setImageBitmap(createBitmap); mCoverView.destroyDrawingCache(); mCoverView.setDrawingCacheEnabled(false);
note: 1. Bitmap createBitmap = Bitmap.createBitmap(mCoverView.getDrawingCache(true));这样是为了防止内存被自动清理时 出现trying to use a recycled bitmap的错误 2. 使用完后记得调用destroyDrawingCache();.setDrawingCacheEnabled(false);释放内存 3. 此方法对于GLSurfaceView不适用
参考网址: http://stackoverflow.com/questions/17634830/canvas-trying-to-use-a-recycled-bitmap-android http://stackoverflow.com/questions/32601187/how-to-save-bitmap-from-glsurfaceview-only-bitmap-not-whole-texture
