2013-07-04 41 views
2

我正在研究Android應用程序,它可以在用戶執行按鈕單擊時從視頻抓取框架,該應用程序被配置爲使用TextureView播放視頻。爲了捕獲幀作爲位圖,我使用:Android TextureView:調用getBitmap時顯示灰色框架的視頻

Bitmap bit = textureView.getBitmap(width, height); 

它工作正常,但「getBitmap」需要相當長的時間(大約150-200毫秒爲640×480幀)。問題出在getBitmap被調用時,灰色框架正在顯示在視圖上。這看起來像是有些東西在輕彈。有沒有辦法解決這個問題?

感謝

+0

您是否嘗試過在一個單獨的線程運行getBitmap方法?獲取位圖仍需要一些時間,但至少不會妨礙顯示回調! –

+0

是否測試過? –

+0

捕獲發生在同一個線程上,捕獲幀需要很多時間 – san

回答

0

您應該使用處理程序,以避免延遲時間

new Handler().post(new Runnable() { 
@Override 
public void run() { 
    try { 
     Bitmap bit = textureView.getBitmap(width, height); 
     //you could save the video frames to use later 
    } catch (Exception ex) { 
     ex.printStackTrace(); 
    } 
}}); 
相關問題