view.getDrawingCache() only works once

后端 未结 1 1466
执念已碎
执念已碎 2020-12-04 22:42

I have a RelativeLayout with a loaded bitmap image using the Touch V2 example from Pragmatic Bookshelf -- http://media.pragprog.com/titles/eband3/code/Touchv2/src/org/exampl

相关标签:
1条回答
  • 2020-12-04 23:27

    To make it work more then once you have to use view.setDrawingCacheEnabled(true) each time before and view.setDrawingCacheEnabled(false) each time after calling view.getDrawingCache(). See the example:

    imageView.setDrawingCacheEnabled(true);
    imageView.buildDrawingCache(true);
    File imageFile = new File(Environment.getExternalStorageDirectory(),
            "Pictures/image.jpg");
    FileOutputStream fileOutputStream = new FileOutputStream(imageFile);
    imageView.getDrawingCache(true).compress(CompressFormat.JPEG, 100,
            fileOutputStream);
    fileOutputStream.close();
    imageView.setDrawingCacheEnabled(false);
    
    0 讨论(0)
提交回复
热议问题