Android--Several forms saved as JPEG files

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.