2017-08-11 5 views
1

私は のようにgetBitmapを使用しましたが、最大120fpsをキャプチャできるcamera2apiのHighspeedcapturesessionでループします。だから毎秒たくさんのビットマップを作成することができます。getbitmapはアプリケーションを遅くします

問題は、私がアプリケーションを実行すると、時間が掛かり、非常に遅くなり、テクスチャフリーズがプレビューされるということです。

どうすればこの問題を解決できますか?

(私はgetbitmapがバッファにあまりにもビットマップの多くを節約すると思います。この権利は、どのようにiアプリを実行している間、いくつかのビットマップを解放することができますか?)

感謝。

答えて

0

AsyncTask

であなたの仕事は、メインスレッド過負荷にならないだろう。この方法で、あなたのビットマップを作成します:

private class MyAsyncTask extends AsyncTask<String, Void, Bitmap> { 
    protected void onPreExecute() { 
     // Runs on the UI thread before doInBackground 
     // Good for toggling visibility of a progress indicator 
     progressBar.setVisibility(ProgressBar.VISIBLE); 
    } 

    protected Bitmap doInBackground(String... strings) { 
     // Some long-running task like downloading an image. 
     Bitmap = downloadImageFromUrl(strings[0]); 
     return someBitmap; 
    } 

    protected void onProgressUpdate(Progress... values) { 
     // Executes whenever publishProgress is called from doInBackground 
     // Used to update the progress indicator 
     progressBar.setProgress(values[0]); 
    } 

    protected void onPostExecute(Bitmap result) { 
     // This method is executed in the UIThread 
     // with access to the result of the long running task 
     imageView.setImageBitmap(result); 
     // Hide the progress bar 
     progressBar.setVisibility(ProgressBar.INVISIBLE); 
    } 
} 

をそして、あなたはmaintのスレッドで何かを実行する必要があるときに再びこの使用します。

MyActivity.runOnUiThread(new Runnable() { 
     @Override 
     public void run() { 
      //Your code to run in GUI thread here 
     }//public void run() { 
}); 
+0

ありがとう、私はこれを試してみます。 –

+0

私は何度も試しましたが、エラーになります。 textureviewからのビットマップの取得は、UI Threadで実行する必要があるためです。それで、他の方法で試してみませんか?私はそこにあることを願っています....ありがとう –

+0

非同期タスクを呼び出す前にビットマップを取得し、そのタスクで重い仕事をしてください。これはあなたの問題を解決する? – GuilhermeFGL

関連する問題