2013-05-17 41 views

回答

2

試試下面的代碼爲截圖: -

// image naming and path to include sd card appending name you choose for file 
String mPath = Environment.getExternalStorageDirectory().toString() + "/" + ACCUWX.IMAGE_APPEND; 

// create bitmap screen capture 
Bitmap bitmap; 
View v1 = mCurrentUrlMask.getRootView(); 
v1.setDrawingCacheEnabled(true); 
bitmap = Bitmap.createBitmap(v1.getDrawingCache()); 
v1.setDrawingCacheEnabled(false); 

OutputStream fout = null; 
imageFile = new File(mPath); 

try { 
    fout = new FileOutputStream(imageFile); 
    bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout); 
    fout.flush(); 
    fout.close(); 

} catch (FileNotFoundException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} catch (IOException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 

每5分鐘拍攝

private final static int INTERVAL = 1000 * 60 * 5; //5 minutes 
Handler m_handler; 

Runnable m_handlerTask = new Runnable() 
{ 
    @Override 
    public void run() { 
      doSomething();// call your screen shot method 
      m_handler.postDelayed(m_handlerTask, INTERVAL); 
    } 
} 

void startRepeatingTask() 
{ 
    m_handlerTask.run(); 
} 

void stopRepeatingTask() 
{ 
    m_handler.removeCallback(m_handlerTask); 
} 

的屏幕截圖link

每5分鐘代碼link

0

使用該代碼:

boolean workDone = false; 
final static int ROUNDTRIP_TIMOUT = 5*60*1000; 
private boolean timeout() { 
     int waited = 0; 
     while (waited < ROUNDTRIP_TIMOUT) { 
      try { 
       Thread.sleep(100); 
      } catch (InterruptedException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      waited += 100; 
      if (waited == ROUNDTRIP_TIMOUT) { 
       captureScreen(); 
       workDone = true; 
      } 
     } 
     return workDone; 
    } 

    public void captureScreen() 
    { 
     // create bitmap screen capture 
     Bitmap bitmap; 
     View v1 = mCurrentUrlMask.getRootView(); 
     v1.setDrawingCacheEnabled(true); 
     bitmap = Bitmap.createBitmap(v1.getDrawingCache()); 
     v1.setDrawingCacheEnabled(false); 
    } 

    if(timeout()) 
     Log.v(TAG , "Screen Capture"); 
    else 
     Log.v(TAG , "Not Done");  
相關問題