public static byte[] encodeJPEG(int w,int h,int[] pixels,float quality) throws IOException {
  BufferedImage bi=new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
  bi.setRGB(0,0,w,h,pixels,0,w);
  pixels=null;
  return encodeJPEG(bi,quality);
}

public static byte [ ] encodeJPEG ( int w , int h , int [ ] pixels , float quality ) throws IOException { BufferedImage bi = new BufferedImage ( w , h , BufferedImage . TYPE_INT_RGB ) ; bi . setRGB ( 0 , 0 , w , h , pixels , 0 , w ) ; pixels = null ; return encodeJPEG ( bi , quality ) ; }
return a byte array that contains the jpeg encoded image .
