1. Use NV21 format Yuvimage class for saving very high 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 ()),, Filecon); The NV21 format picture is compressed to a JPEG with a mass of 70, and the JPEG data stream}catch (IOException e) {e.printstacktrace () is obtained; }}//2. Using Bitmap class bitmap bmp = Bitmapfactory.decodefile (Picturefile.getpath ()); FileOutputStream Fileoutstream = Null;fileoutstream = new FileOutputStream (file); Bmp.compress ( Bitmap.CompressFormat.JPEG, Fileoutstream); Outputs the bitmap to the specified file Fileoutstream.flush (); Fileoutstream.close ();//3. Direct use of Save byte[] data fileoutputstream fos = new FileOutputStream (Picturefile.getpath ()); Get file Output streamfos.write (bytes); Written to the Filefos.close ();
Android--Several forms saved as JPEG files