Android-save several formats as jpeg files
// 1. the YuvImage class in NV21 format is used for storage efficiency. String fileName = "IMG _" + String. valueOf (index) + ". jpg "; File sdRoot = Environment. getExternalStorageDirectory (); String dir = "/picture/"; File mkDir = new File (sdRoot, dir); if (! MkDir. exists () {mkDir. mkdirs ();} File pictureFile = new File (sdRoot, dir + fileName); if (! PictureFile. exists () {try {pictureFile. createNewFile (); FileOutputStream filecon = new FileOutputStream (pictureFile); YuvImage image = new YuvImage (data, ImageFormat. NV21, size. width, size. height, null); image. compressToJpeg (new Rect (0, 0, image. getWidth (), image. getHeight (), 70, filecon); // compress an NV21 image with a quality of 70 to Jpeg and obtain the JPEG data stream} catch (IOException e) {e. printStackTrace () ;}// 2. bitmap bmp = BitmapFactory is used. decodeFile (pictureFile. getPath (); FileOutputStream fileOutStream = null; fileOutStream = new FileOutputStream (file); bmp. compress (Bitmap. compressFormat. JPEG, 100, fileOutStream); // outputs the bitmap to the specified file. flush (); fileOutStream. close (); // 3. save byte [] data FileOutputStream fos = new FileOutputStream (pictureFile. getPath (); // Get file output streamfos. write (bytes); // Written to the filefos. close ();