2011-04-25 3 views
9

मेरे पास View है और मैं इसे कहीं भी स्टोर करने के लिए इसे एक छवि में रूपांतरित करना चाहता हूं। लेकिन मैं इस छवि को View में कैसे परिवर्तित कर सकता हूं?मैं व्यू को एक ड्रायबल में कैसे परिवर्तित कर सकता हूं?

उत्तर

8

देख सकते हैं और एसडी कार्ड में स्टोर की छवि ले लिए यह प्रयास करें ..

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 हो रही है ** इस कोड लाइन के लिए 'बिटमैप बी.एम. = Bitmap.createBitmap (देखें .getDrawingCache()); 'कारण क्या हो सकता है? – AnujAroshA

+0

** समाधान ** मिला। यहां जाएं [http://stackoverflow.com/a/4618030/833007) – AnujAroshA

संबंधित मुद्दे

 संबंधित मुद्दे