2011-04-25 42 views

回答

8

嘗試此觀點,並存儲在SD卡將影像..

View view = TextView.getRootView(); 
//You can use any view of your View instead of TextView 

if (view != null) 
{ 
    System.out.println("view is not null....."); 
    view.setDrawingCacheEnabled(true); 
    view.buildDrawingCache(); 
    Bitmap bm = view.getDrawingCache(); 

    try 
    { 
     if (bm != null) 
     { 
      String dir = Environment.getExternalStorageDirectory().toString(); 
      System.out.println("bm is not null....."); 
      OutputStream fos = null; 
      File file = new File(dir,"sample.JPEG"); 
      fos = new FileOutputStream(file); 
      BufferedOutputStream bos = new BufferedOutputStream(fos); 
      bm.compress(Bitmap.CompressFormat.JPEG, 50, bos); 
      bos.flush(); 
      bos.close(); 
     } 
    } 
    catch(Exception e) 
    { 
     System.out.println("Error="+e); 
     e.printStackTrace(); 
    } 
} 
5
  1. 啓用視圖繪製緩存:

    view.setDrawingCacheEnabled(true); 
    
  2. 從緩存中創建位圖:

    bitmap = Bitmap.createBitmap(view.getDrawingCache()); 
    
  3. 保存位圖的地方......

  4. 禁用繪圖緩存:

    view.setDrawingCacheEnabled(false); 
    
+2

我得到一個NullPointerException異常** **此行代碼'位圖BM = Bitmap.createBitmap (view.getDrawingCache());'可能是什麼原因? – AnujAroshA 2012-09-06 06:27:42

+0

找到**解決方案**。訪問[這裏](http://stackoverflow.com/a/4618030/833007) – AnujAroshA 2012-09-06 07:02:40

相關問題