title: Displaying YUV Image in Android
body: <p>In my application, we need to display the Video frame receives from server to our android application,<br>
  Server is sending video data @ 50 frame per second, having encoded in WebM i.e. using libvpx to encode and decode the images, </p>
  
  <p>Now after decoding from libvpx its getting YUV data, that we can displayed over the image layout,</p>
  
  <p>the current implementation is something like this,</p>
  
  <p>In JNI / Native C++ code, we are converting YUV data to RGB Data 
  In Android framework, calling </p>
  
  <pre><code>public Bitmap createImgae(byte[] bits, int width, int height, int scan) {
      Bitmap bitmap=null;
      System.out.println("video: creating bitmap");
      //try{
  
              bitmap = Bitmap.createBitmap(width, height,
                      Bitmap.Config.ARGB_8888);
              bitmap.copyPixelsFromBuffer(ByteBuffer.wrap(bits));     
  
      //}catch(OutOfMemoryError ex){
  
      //}
              System.out.println("video: bitmap created");
      return bitmap;
  }  
  </code></pre>
  
  <p>To create the bitmap image , </p>
  
  <p>to display the image over imageView using following code,  </p>
  
  <pre><code>               img = createImgae(imgRaw, imgInfo[0], imgInfo[1], 1);
                 if(img!=null &amp;&amp; !img.isRecycled()){
  
                      iv.setImageBitmap(img);
                      //img.recycle();
                      img=null;
                      System.out.println("video: image displayed");
                  }
  </code></pre>
  
  <p>My query is, overall this function is taking approx 40 ms, is there any way to optimize it,<br>
  1 -- Is there any way to display YUV data to imageView ?  </p>
  
  <p>2 -- Is there any other way to create Image( Bitmap image) from RGB data ,  </p>
  
  <p>3 -- I believe i am always creating image, but i suppose i should create bitmap only once and do / supply new buffer always, as and when we received.<br>
   please share your views. </p>