Save a picture String FileName = "Img_" + string.valueof (Index) + ". jpg"; JPEG file name definition file Sdroot = environment.getexternalstoragedirectory (); System path String dir = "/jpeg/"; Folder name File MkDir = new file (Sdroot, dir); if (!mkdir.exists ()) { mkdir.mkdirs (); Directory does not exist, create}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, width, height, null); Save NV21 data to Yuvimage //image compression image.compresstojpeg ( new Rect (0, 0, image.getwidth (), Image.getheight ()), Filecon); Compress the NV21 format picture to a JPEG with a mass of 70 and get the JPEG data stream }catch (IOException e) { e.printstacktrace (); }}
This approach, often in
Camera.PreviewCallbackUsed in:
@Overridepublic void Onpreviewframe (byte[] data, Camera camera) {}
Compress the NV21 data into JPEG and get the JPEG byte data, unzip the JPEG byte data into a single bitmap
@Overridepublic void Onpreviewframe (byte[] bytes, camera camera) { yuvimage image = New Yuvimage (bytes, IMAGEFORMAT.N V21, width, height, null); IMAGEFORMAT.NV21 640 480 bytearrayoutputstream outputsteam = new Bytearrayoutputstream (); Image.compresstojpeg (New Rect (0, 0, image.getwidth (), Image.getheight ()),, Outputsteam); The NV21 format picture, compressed to a quality of 70 jpeg, and get JPEG data stream byte[] jpegdata = Outputsteam.tobytearray (); Get byte data from outputsteam options options = new Bitmapfactory.options (); Options.insamplesize = 1; Bitmap bmp = Bitmapfactory.decodestream (Jpegdata, NULL, options);}
http://my.oschina.net/eclipse88/blog/80115
Android-Save NV21 image as jpeg