捕获屏幕截图的正确方法

时间:2012-03-01 07:46:52

标签: android

我遇到了两种制作屏幕截图的方法。

我在想,

  1. 这两个例子有什么不同?这是正确的方法吗?
  2. 示例1 是否可能出现资源/内存泄漏问题?

  3. 示例1

    View v = rootView.findViewById(R.id.layout1);
    if (v != null) {
        v.setDrawingCacheEnabled(true);
        Bitmap bitmap = v.getDrawingCache();
        canvas.drawBitmap(bitmap, dummyMatrix, null);
        // Possible resource/ memory leak?
    }
    

    示例2

    View v = rootView.findViewById(R.id.layout1);
    if (v != null) {
        v.buildDrawingCache();
        Bitmap bitmap = v.getDrawingCache();
        canvas.drawBitmap(bitmap, dummyMatrix, null);
        v.destroyDrawingCache();   
    }
    

1 个答案:

答案 0 :(得分:2)

我个人会选择示例2.我喜欢您在继续使用该程序时清除缓存的方式。

http://codehenge.net/blog/2011/06/android-development-tutorial-asynchronous-lazy-loading-and-caching-of-listview-images/

相关问题