2011-04-25 15 views

Respuesta

8

Intenta esta toma la imagen de vista y almacenar en la tarjeta SD para ..

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. Habilitar dibujo caché en la vista:

    view.setDrawingCacheEnabled(true); 
    
  2. Crear un mapa de bits de la caché:

    bitmap = Bitmap.createBitmap(view.getDrawingCache()); 
    
  3. Guardar el mapa de bits siempre que sea ...

  4. Desactivar caché de dibujo:

    view.setDrawingCacheEnabled(false); 
    
+2

Estoy recibiendo una NullPointerException ** ** para esta línea de código de mapa de bits 'bm = Bitmap.createBitmap (view.getDrawingCache()); '¿Cuál puede ser el motivo? – AnujAroshA

+0

Encontrado la ** solución **. Visita [aquí] (http://stackoverflow.com/a/4618030/833007) – AnujAroshA

Cuestiones relacionadas