Android Image Processing

Source: Internet
Author: User

Android Image Processing

Android image processing summary:

1: when taking a photo on Android, we may encounter some statuses. For example, if you take a photo on a Samsung mobile phone, the photo may be automatically rotated after the photo is taken, in this regard, the rotating photo is restored:

 

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 image is rotated, change the rotation level.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 images, the image size is a big problem, because the photo taken by mainstream Android phones should be at least 3 m, if you need a filter or upload, it will take a lot of time. In fact, most of us do not need images of high quality. When the image resolution is high, it only works when you view the large image. on the mobile phone screen, you do not need images of high quality. Therefore, if you do not need to crop the image, you can reduce the image resolution proportionally. Sample Code:

 

public String scaleDown(String path,Context context){    Bitmap orignalB=BitmapFactory.decodeFile(path);    float ratio = Math.min((float) 974 / orignalB.getWidth(),(float) 974 / orignalB.getHeight());    int width = Math.round((float) ratio * orignalB.getWidth());    int height = 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();    return newpath;}

 

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.