1. 程式人生 > >安卓從imageview中獲得bitmap的方法

安卓從imageview中獲得bitmap的方法

第一種:

使用setDrawingCacheEnabled()和getDrawingCache()這兩種方法,第一個是為了設定是否開啟快取,第二個就可以直接獲得imageview中的快取,一般來說需要在獲得快取以後setDrawingCacheEnabled設定為false,因為這樣才能讓之前的快取去掉,不會影響後來新的快取。

    ImageView image = (ImageView) view.getTag();  
    Matrix max = new Matrix();  
    image.setDrawingCacheEnabled(true);  
    Bitmap bm = image.getDrawingCache();  

第二種:
Bitmap bm =((BitmapDrawable) ((ImageView) image).getDrawable()).getBitmap();

直接強行獲得內部的圖片。