title: Display a stream of bitmaps at 60fps smoothly on Android 4.x
body: <p>(This is due to the limitations of the server software I will be using, if I could change it, I would).</p>
  
  <p>I am receiving a sequence of 720x480 JPEG files (about 6kb in size), over a socket. I have benchmarked the network, and have found that I am capable of receiving those JPEGs smoothly, at 60FPS.</p>
  
  <p>My current drawing operation is on a Nexus 10 display of 2560x1600, and here's my decoding method, once I have received the byte array from the socket:</p>
  
  <pre><code>public static void decode(byte[] tmp, Long time) {
      try {
          BitmapFactory.Options options = new BitmapFactory.Options();
          options.inPreferQualityOverSpeed = false;
          options.inDither = false;
          Bitmap bitmap = BitmapFactory.decodeByteArray(tmp, 0, tmp.length, options);
          Bitmap background = Bitmap.createScaledBitmap
                  (bitmap, MainActivity.screenwidth, MainActivity.screenheight, false);
          background.setHasAlpha(false);
              Canvas canvas = MainActivity.surface.getHolder().lockCanvas();
              canvas.drawColor(Color.BLACK);
              canvas.drawBitmap(background, 0, 0, new Paint());
              MainActivity.surface.getHolder().unlockCanvasAndPost(canvas);
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>As you can see, I am clearing the canvas from a SurfaceView, and then drawing the Bitmap to the SurfaceView. My issue is that it is very, very, slow.</p>
  
  <p>Some tests based on adding System.currentTimeMillis() before and after the lock operation result in approximately a 30ms difference between getting the canvas, drawing the bitmap, and then pushing the canvas back. The displayed SurfaceView is <em>very</em> laggy, sometimes it jumps back and forth, and the frame rate is terrible.</p>
  
  <p>Is there a referred method for drawing like this? Again, I can't modify what I'm getting from the server, but I'd like the bitmaps to be displayed at 60FPS when possible.</p>
  
  <p>(I've tried setting the contents of an ImageView, and am receiving similar results). I have no other code in the SurfaceView that could impact this. I have set the holder to the RGBA_8888 format:</p>
  
  <pre><code>    getHolder().setFormat(PixelFormat.RGBA_8888);
  </code></pre>
  
  <p>Is it possible to convert this stream of Bitmaps into a VideoView? Would that be faster?</p>
  
  <p>Thanks.</p>