Android Photos rotate and save

Source: Internet
Author: User

    /*** Read Picture properties: Angle of rotation *@paramPath Image Absolute path *@returndegree angle of rotation*/     Public intreadpicturedegree (String path) {intdegree = 0; Try{exifinterface Exifinterface=Newexifinterface (path); intOrientation =Exifinterface.getattributeint (exifinterface.tag_orientation, exifinterface.orientation_normal); Switch(orientation) { CaseExifInterface.ORIENTATION_ROTATE_90:degree= 90;  Break;  CaseExifInterface.ORIENTATION_ROTATE_180:degree= 180;  Break;  CaseExifInterface.ORIENTATION_ROTATE_270:degree= 270;  Break; }        } Catch(IOException e) {e.printstacktrace (); }        returndegree; } /** Rotate picture * @param angle * @param bitmap * @return Bitmap*/     PublicBitmap Rotaingimageview (intangle, Bitmap Bitmap) {         //Rotate picture ActionMatrix Matrix =NewMatrix ();       Matrix.postrotate (angle); //Create a new picture       returnBitmap.createbitmap (Bitmap, 0, 0, bitmap.getwidth (), Bitmap.getheight (), Matrix,true); }/*** * save bitmap in SD JPEG format * *@paramBitmap * Picture bitmap *@paramFilePath * To save the picture path *@paramQuality * Compression quality value*/     Public voidSaveImage (Bitmap Bitmap, String FilePath,intquality) {FileOutputStream FileOutputStream=NULL; Try{FileOutputStream=NewFileOutputStream (FilePath);            Bitmap.compress (compressformat.jpeg, quality, fileoutputstream);            Fileoutputstream.flush ();            Fileoutputstream.close (); //If the picture has not yet been recycled, force the recycle            if(!bitmap.isrecycled ())                {bitmap.recycle ();            System.GC (); }        } Catch(Exception e) {}}bitmap=imagecompress.decodesampledbitmapfromresource (filename, 480, 800); //Picture Rotation                    intdegree =imageutils.readpicturedegree (filename); Bitmap=Imageutils.rotaingimageview (degree, bitmap); //save picture to sd card//imagecompress.saveimage (bitmap, filename);Imagecompress.saveimage (bitmap, filename,90);
View Code

/*** * Dynamic Setting insamplesize multiple * *@parampathName * Picture path *@paramReqwidth * The width to compress *@paramreqheight * Height to compress *@return     */     Public StaticBitmap Decodesampledbitmapfromresource (String pathName,intReqwidth,intreqheight) {        //first set the injustdecodebounds=true to get the picture size        FinalBitmapfactory.options Options =Newbitmapfactory.options (); Options.injustdecodebounds=true;        Bitmapfactory.decodefile (pathName, Options); //calculate the value of a insamplesizeOptions.insamplesize =calculateinsamplesize (Options, Reqwidth, reqheight); //decode the image generation based on the computed insamplesize bitmapOptions.injustdecodebounds =false; returnbitmapfactory.decodefile (pathName, Options); }
View Code

Android Photos rotate and save

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.