Note that there are some explanatory texts on larger screens.

plurals
  1. POBitmapFactory.Options.inBitmap causes tearing when switching ImageView bitmap often
    primarykey
    data
    text
    <p>I've encountered a situation where I have to display images in a slideshow that switches image very fast. The sheer number of images makes me want to store the JPEG data in memory and decode them when I want to display them. To ease on the Garbage Collector, I'm using <a href="http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inBitmap" rel="noreferrer">BitmapFactory.Options.inBitmap</a> to reuse bitmaps.</p> <p>Unfortunately, this causes rather severe tearing, I've tried different solutions such as synchronization, semaphores, alternating between 2-3 bitmaps, however, none seem to fix the problem.</p> <p>I've set up an example project which demonstrates this issue over at GitHub; <a href="https://github.com/Berglund/android-tearing-example" rel="noreferrer">https://github.com/Berglund/android-tearing-example</a></p> <p>I've got a thread which decodes the bitmap, sets it on the UI thread, and sleeps for 5 ms:</p> <pre><code>Runnable runnable = new Runnable() { @Override public void run() { while(true) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 1; if(bitmap != null) { options.inBitmap = bitmap; } bitmap = BitmapFactory.decodeResource(getResources(), images.get(position), options); runOnUiThread(new Runnable() { @Override public void run() { imageView.setImageBitmap(bitmap); } }); try { Thread.sleep(5); } catch (InterruptedException e) {} position++; if(position &gt;= images.size()) position = 0; } } }; Thread t = new Thread(runnable); t.start(); </code></pre> <p>My idea is that ImageView.setImageBitmap(Bitmap) draws the bitmap on the next vsync, however, we're probably already decoding the next bitmap when this happens, and as such, we've started modifying the bitmap pixels. Am I thinking in the right direction?</p> <p>Has anyone got any tips on where to go from here?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload