Android image processing

Source: Internet
Author: User

Android Image processing finishing Summary:

1:android Photos We will encounter some state, such as using a Samsung phone to take pictures, it is possible that after the photo is taken, the photo will automatically rotate, the following aspect is to restore the rotated photos back:

 Bitmap Bitmap = Bitmapfactory.decodefile (Const.ACT_CREATE_PIC_PATH.concat (photoname));
int angle= imageutils.getexiforientation (Const.ACT_CREATE_PIC_PATH.concat (photoname));
if (angle!=0) {//If the photo appears rotated then change the rotation degree
Matrix matrix = new Matrix ();
Matrix.postrotate (angle);
bitmap = bitmap.createbitmap (bitmap,0, 0, Bitmap.getwidth (), Bitmap.getheight (), Matrix, True);
}


2: If the Android app needs to process and upload pictures, then the size of the picture is a big problem, because the mainstream Android phone photos to take at least 3M, if your picture needs filter or upload, it will consume a lot of time. In fact, most of the time we do not need the quality of the picture, the image resolution is high when the view is only useful when looking at a large image, on the phone screen to see the picture does not need the high quality pictures. So, if you do not need to crop, you can reduce the resolution of the picture by its own proportions. Example code:

 PublicStringScaledown(String Path,Context context)
{
Bitmap orignalb=bitmapfactory.DecodeFile(path);
floatRatio = Math.min((float)974/Orignalb.getwidth (),(float)974/Orignalb.getheight ());
intwidth = Math.round((float) ratio * ORIGNALB.GETWIDTH ());
intHeight = Math.round((float) ratio * Orignalb.getheight ());

Bitmap newb = Bitmap.Createscaledbitmap(Orignalb,Width,Height, True);
String imgname=path.substring (Path.lastindexof ("/")+1,Path.length ()-1);
String userid= Userhelper.getUserId(context);
String Newpath=createdirectoryandsavefile (newb,Userid+system.Currenttimemillis()+". jpg");
Orignalb.recycle ();
Newb.recycle ();
returnNewPath;
}

Android image processing

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.