public byte[] convertNv21toJpeg(byte[] data_copy,int w,int h,int[] strides){
  Log.e(TAG,"TIMER_BEGIN NV21 to Jpeg Conversion.");
  YuvImage yuvImage=new YuvImage(data_copy,ImageFormat.NV21,w,h,strides);
  ByteArrayOutputStream postViewBytes=new ByteArrayOutputStream();
  yuvImage.compressToJpeg(new Rect(0,0,w,h),90,postViewBytes);
  try {
    postViewBytes.flush();
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
  Log.e(TAG,"TIMER_END NV21 to Jpeg Conversion.");
  return postViewBytes.toByteArray();
}

public byte [ ] convertNv21toJpeg ( byte [ ] data_copy , int w , int h , int [ ] strides ) { Log . e ( TAG , "TIMER_BEGIN NV21 to Jpeg Conversion." ) ; YuvImage yuvImage = new YuvImage ( data_copy , ImageFormat . NV21 , w , h , strides ) ; ByteArrayOutputStream postViewBytes = new ByteArrayOutputStream ( ) ; yuvImage . compressToJpeg ( new Rect ( 0 , 0 , w , h ) , 90 , postViewBytes ) ; try { postViewBytes . flush ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } Log . e ( TAG , "TIMER_END NV21 to Jpeg Conversion." ) ; return postViewBytes . toByteArray ( ) ; }
wraps the android built - in yuv to jpeg conversion routine . pass in a valid nv21 image and get back a compressed jpeg buffer . a good default jpeg compression implementation that should be supported on all platforms .
